Kims12 commited on
Commit
d366591
ยท
verified ยท
1 Parent(s): a7ea647

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -69
app.py CHANGED
@@ -235,90 +235,100 @@ def run_example_2():
235
  result_img.save(output_path, "WEBP")
236
  return result_img, status, final_prompt
237
 
238
- # -------------------------------------------------------------------
239
- # ์˜ˆ์ œ ์ ์šฉ ๋ถ€๋ถ„ (์ฐธ์กฐ ์ฝ”๋“œ ์ ์šฉ)
240
- # -------------------------------------------------------------------
241
- # Set up the interaction with two outputs.
242
- submit_btn.click(
243
- fn=process_image_and_prompt,
244
- inputs=[image_input, prompt_input, gemini_api_key],
245
- outputs=[output_gallery, output_text],
246
- )
247
-
248
- gr.Markdown("## Try these examples", elem_classes="gr-examples-header")
249
-
250
- examples = [
251
- ["data/1.webp", 'change text to "AMEER"', ""],
252
- ["data/2.webp", "remove the spoon from hand only", ""],
253
- ["data/3.webp", 'change text to "Make it "', ""],
254
- ["data/1.jpg", "add joker style only on face", ""],
255
- ["data/1777043.jpg", "add joker style only on face", ""],
256
- ["data/2807615.jpg", "add lipstick on lip only", ""],
257
- ["data/76860.jpg", "add lipstick on lip only", ""],
258
- ["data/2807615.jpg", "make it happy looking face only", ""],
259
- ]
260
-
261
- gr.Examples(
262
- examples=examples,
263
- inputs=[image_input, prompt_input],
264
- elem_id="examples-grid"
265
- )
266
- # -------------------------------------------------------------------
267
-
268
- # ๊ธฐ์กด Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ (์˜ˆ์ œ ์ ์šฉ ์™ธ ๋‹ค๋ฅธ ์ฝ”๋“œ๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€)
269
  with gr.Blocks() as demo:
270
  gr.HTML(
271
  """
272
  <div style="text-align: center; margin-bottom: 1rem;">
273
- <h1>Gemini for Image Editing</h1>
274
- <p>Upload an image and enter a prompt to generate outputs.</p>
275
  </div>
276
  """
277
  )
278
 
279
  with gr.Row():
280
  with gr.Column():
281
- image_input = gr.Image(
282
- type="pil",
283
- label="Upload Image",
284
- image_mode="RGBA",
285
- elem_id="image-input"
286
- )
287
- gemini_api_key = gr.Textbox(
288
- lines=1,
289
- placeholder="Enter Gemini API Key (optional)",
290
- label="Gemini API Key (optional)"
291
- )
292
  prompt_input = gr.Textbox(
293
- lines=2,
294
- placeholder="Enter prompt here...",
295
- label="Prompt"
296
  )
297
- submit_btn = gr.Button("Generate")
 
 
 
 
 
 
298
  with gr.Column():
299
- output_gallery = gr.Gallery(label="Generated Outputs")
300
- output_text = gr.Textbox(
301
- label="Gemini Output",
302
- placeholder="Text response will appear here if no image is generated."
303
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
 
305
- gr.Markdown("## Try these examples", elem_classes="gr-examples-header")
 
 
306
 
307
- examples = [
308
- ["data/1.webp", 'change text to "AMEER"', ""],
309
- ["data/2.webp", "remove the spoon from hand only", ""],
310
- ["data/3.webp", 'change text to "Make it "', ""],
311
- ["data/1.jpg", "add joker style only on face", ""],
312
- ["data/1777043.jpg", "add joker style only on face", ""],
313
- ["data/2807615.jpg", "add lipstick on lip only", ""],
314
- ["data/76860.jpg", "add lipstick on lip only", ""],
315
- ["data/2807615.jpg", "make it happy looking face only", ""],
316
- ]
317
 
318
- gr.Examples(
319
- examples=examples,
320
- inputs=[image_input, prompt_input],
321
- elem_id="examples-grid"
 
 
 
 
 
 
 
322
  )
323
 
324
- demo.queue(max_size=50).launch()
 
 
235
  result_img.save(output_path, "WEBP")
236
  return result_img, status, final_prompt
237
 
238
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  with gr.Blocks() as demo:
240
  gr.HTML(
241
  """
242
  <div style="text-align: center; margin-bottom: 1rem;">
243
+ <h1>๊ฐ„๋‹จํ•œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ๊ธฐ (์˜ˆ์ œ ํฌํ•จ)</h1>
244
+ <p>์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ฑฐ๋‚˜ ์•„๋ž˜ ์˜ˆ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์ฒ˜๋ฆฌ๋œ ๊ฒฐ๊ณผ๊ฐ€ down ํด๋”์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.</p>
245
  </div>
246
  """
247
  )
248
 
249
  with gr.Row():
250
  with gr.Column():
251
+ with gr.Row():
252
+ image1_input = gr.Image(type="pil", label="#1", image_mode="RGB")
253
+ image2_input = gr.Image(type="pil", label="#2", image_mode="RGB")
254
+ image3_input = gr.Image(type="pil", label="#3", image_mode="RGB")
 
 
 
 
 
 
 
255
  prompt_input = gr.Textbox(
256
+ lines=3,
257
+ placeholder="ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋น„์›Œ๋‘๋ฉด ์ž๋™ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.",
258
+ label="ํ”„๋กฌํ”„ํŠธ (์„ ํƒ ์‚ฌํ•ญ)"
259
  )
260
+ with gr.Row():
261
+ image_change_btn = gr.Button("์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ")
262
+ text_remove_btn = gr.Button("๊ธ€์ž์ง€์šฐ๊ธฐ")
263
+ clothes_change_btn = gr.Button("์˜ท๋ฐ”๊พธ๊ธฐ")
264
+ background_change_btn = gr.Button("๋ฐฐ๊ฒฝ๋ฐ”๊พธ๊ธฐ")
265
+ composite_product_btn = gr.Button("์ด๋ฏธ์ง€ ํ•ฉ์„ฑ(์ƒํ’ˆํฌํ•จ)")
266
+ submit_btn = gr.Button("์ด๋ฏธ์ง€ ์ƒ์„ฑ", variant="primary")
267
  with gr.Column():
268
+ output_image = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
269
+ output_text = gr.Textbox(label="์ƒํƒœ ๋ฉ”์‹œ์ง€")
270
+ prompt_display = gr.Textbox(label="์‚ฌ์šฉ๋œ ํ”„๋กฌํ”„ํŠธ (์˜์–ด)", visible=True)
271
+
272
+ # ์„ ํƒ ์˜ต์…˜ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€ ์—…๋ฐ์ดํŠธ (ํ•œ๊ตญ์–ด ๋ฌธ๊ตฌ)
273
+ image_change_btn.click(
274
+ fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ [๋‹ค๋ฅธ ๋ชจ์Šต]์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ.",
275
+ inputs=[],
276
+ outputs=prompt_input
277
+ )
278
+ text_remove_btn.click(
279
+ fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ [์ค‘๊ตญ์–ด๋ฅผ ๋ชจ๋‘]๋ฅผ ์ œ๊ฑฐํ•˜๋ผ.",
280
+ inputs=[],
281
+ outputs=prompt_input
282
+ )
283
+ clothes_change_btn.click(
284
+ fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ ์ธ๋ฌผ ์˜์ƒ์„ #2 ์ด๋ฏธ์ง€์˜ ์˜์ƒ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ.",
285
+ inputs=[],
286
+ outputs=prompt_input
287
+ )
288
+ background_change_btn.click(
289
+ fn=lambda: "#1 ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์„ #2 ์ด๋ฏธ์ง€์˜ ๋ฐฐ๊ฒฝ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ผ.",
290
+ inputs=[],
291
+ outputs=prompt_input
292
+ )
293
+ composite_product_btn.click(
294
+ fn=lambda: "#1 ์ด๋ฏธ์ง€์™€ #2 ์ด๋ฏธ์ง€(๋˜๋Š” #3 ์ด๋ฏธ์ง€)๋ฅผ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•ฉ์„ฑํ•˜๋ผ.",
295
+ inputs=[],
296
+ outputs=prompt_input
297
+ )
298
+
299
+ submit_btn.click(
300
+ fn=process_and_show_prompt,
301
+ inputs=[image1_input, image2_input, image3_input, prompt_input],
302
+ outputs=[output_image, output_text, prompt_display],
303
+ )
304
 
305
+ with gr.Row():
306
+ example1_btn = gr.Button("์˜ˆ์ œ 1 ์‹คํ–‰")
307
+ example2_btn = gr.Button("์˜ˆ์ œ 2 ์‹คํ–‰")
308
 
309
+ example1_btn.click(
310
+ fn=run_example_1,
311
+ inputs=[],
312
+ outputs=[output_image, output_text, prompt_display]
313
+ )
314
+ example2_btn.click(
315
+ fn=run_example_2,
316
+ inputs=[],
317
+ outputs=[output_image, output_text, prompt_display]
318
+ )
319
 
320
+ gr.Markdown(
321
+ """
322
+ ### ์‚ฌ์šฉ ๋ฐฉ๋ฒ•:
323
+
324
+ 1. **์ž๋™ ํ•ฉ์„ฑ**: ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋น„์›Œ๋‘๋ฉด ์ž๋™์œผ๋กœ ํ•ฉ์„ฑ๋ฉ๋‹ˆ๋‹ค.
325
+ 2. **์ด๋ฏธ์ง€ ์ฐธ์กฐ**: #1, #2, #3์œผ๋กœ ๊ฐ ์ด๋ฏธ์ง€๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
326
+ 3. **์˜ˆ์ œ ์‹คํ–‰**: ์•„๋ž˜ "์˜ˆ์ œ 1 ์‹คํ–‰" ๋˜๋Š” "์˜ˆ์ œ 2 ์‹คํ–‰" ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด down ํด๋”์˜ ์ž…๋ ฅ ์ด๋ฏธ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜์—ฌ ๊ฒฐ๊ณผ๊ฐ€ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
327
+ 4. **์„ ํƒ ์˜ต์…˜**: ์œ„์˜ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ๋ž€์— ํ•œ๊ตญ์–ด ๋ฌธ๊ตฌ๊ฐ€ ์ฑ„์›Œ์ง€๊ณ , ์ดํ›„ Geminiโ€‘2.0โ€‘flash ๋ชจ๋ธ์„ ํ†ตํ•ด ์˜์–ด๋กœ ๋ฒˆ์—ญ๋˜์–ด ์‹ค์ œ API ํ˜ธ์ถœ ํ”„๋กฌํ”„ํŠธ๋กœ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.
328
+
329
+ > **ํŒ**: ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ง์ ‘ ์ˆ˜์ •ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
330
+ """
331
  )
332
 
333
+ if __name__ == "__main__":
334
+ demo.launch(share=True)