longshiine
feat: ํ…Œ๋งˆ ๋ณ€๊ฒฝ
f9652c8
import gradio as gr
from infra import image_processing_single, image_processing_batch
with gr.Blocks(theme='freddyaboulton/dracula_revamped', title='Image Generator') as demo:
gr.HTML("""
<h1>Product Image Generator</h1>
<p>1. ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.<p>
<p>2-1. Single ๋ชจ๋“œ์˜ ๊ฒฝ์šฐ, ์ด๋ฏธ์ง€์˜ ๋งํฌ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.<p>
<p>2-2. Batch ๋ชจ๋“œ์˜ ๊ฒฝ์šฐ, ์ด๋ฏธ์ง€ ๋งํฌ๋“ค์ด ํฌํ•จ๋œ .txt ํŒŒ์ผ(ํ˜•์‹ = ๋งํฌ1(์—”ํ„ฐ) ๋งํฌ2(์—”ํ„ฐ) ..)์„ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.<p>
<p>3. Generate Images ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ œํ’ˆ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”.<p>
""")
with gr.Row(elem_classes="input_box"):
with gr.Column():
background_image = gr.Image(label="Background Image", type="pil", height=300)
gr.Examples(
examples=[["examples/background_1.png"], ["examples/background_2.png"], ["examples/background_3.png"], ["examples/background_4.png"]], # ์˜ˆ์ œ ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ ๋ฆฌ์ŠคํŠธ
inputs=background_image, # ์˜ˆ์ œ๋ฅผ ํด๋ฆญํ–ˆ์„ ๋•Œ ํ•ด๋‹น ์ด๋ฏธ์ง€๊ฐ€ ์ด input์— ์ ์šฉ๋จ
label="์˜ˆ์ œ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€")
with gr.Tab("Single Mode"):
with gr.Column():
product_image_size = gr.Slider(512, 1024, value=800, label="์ œํ’ˆ ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ")
link = gr.Textbox(label="Image URL")
gr.Examples(
examples=["https://url.kr/yx85be", "https://url.kr/if4wxo"],
inputs=link,
label="์˜ˆ์ œ ์ด๋ฏธ์ง€ ๋งํฌ"
)
btn_single = gr.Button("Generate Images")
with gr.Tab("Batch Mode"):
with gr.Column():
product_image_size_batch = gr.Slider(512, 1024, value=800, label="์ œํ’ˆ ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ")
gr.HTML("<div>๋งํฌ1(์—”ํ„ฐ) ๋งํฌ2(์—”ํ„ฐ) ... ์œผ๋กœ ๊ตฌ์„ฑ๋œ .txt ํŒŒ์ผ์„ ์—…๋กœ๋“œ</div>")
links = gr.File(label="Image URLs (.txt file)", height=100)
gr.Examples(
examples=[["examples/links.txt"]],
inputs=links,
label="์˜ˆ์ œ .txt ํŒŒ์ผ"
)
btn_batch = gr.Button("Generate Images")
gr.HTML("""
<br><br>
<h1>์ƒ์„ฑ ๊ฒฐ๊ณผ ํ™•์ธ</h1>
<p>์ƒ์„ฑ์€ 1๊ฐœ ์ด๋ฏธ์ง€ ๋‹น 15~30์ดˆ ์†Œ์š”๋˜๋ฉฐ(๋ฐฐ๊ฒฝ์ œ๊ฑฐ AI ๋ชจ๋“ˆ ์ฒ˜๋ฆฌ์‹œ๊ฐ„), ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.</p>
<p>1. ์ฒซ๋ฒˆ์งธ ์ด๋ฏธ์ง€์— ๋Œ€ํ•œ ํ”„๋ฆฌ๋ทฐ(3๊ฐœ ํƒ€์ž…)</p>
<p>2. ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€ ์ „์ฒด๊ฐ€ ๋‹ด๊ธด ZIP ํŒŒ์ผ(results.zip) ๋‹ค์šด๋กœ๋“œ ๋งํฌ๊ฐ€ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค</p>
""")
with gr.Row():
preview = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery", columns=[3], rows=[1], object_fit="contain", height="auto")
output_zip = gr.File(label="Download Result Zip File")
# evnets
btn_single.click(fn=image_processing_single, inputs=[background_image, link, product_image_size], outputs=[preview, output_zip], api_name="image_processing_single")
btn_batch.click(fn=image_processing_batch, inputs=[background_image, links, product_image_size_batch], outputs=[preview, output_zip], api_name="image_processing_batch")
demo.launch()