Kims12 commited on
Commit
36c0960
ยท
verified ยท
1 Parent(s): e703784

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -79
app.py CHANGED
@@ -235,100 +235,61 @@ def run_example_2():
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)
 
235
  result_img.save(output_path, "WEBP")
236
  return result_img, status, final_prompt
237
 
238
+
239
+ # ๊ธฐ์กด Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ (์˜ˆ์ œ ์ ์šฉ ์™ธ ๋‹ค๋ฅธ ์ฝ”๋“œ๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€)
240
  with gr.Blocks() as demo:
241
  gr.HTML(
242
  """
243
  <div style="text-align: center; margin-bottom: 1rem;">
244
+ <h1>Gemini for Image Editing</h1>
245
+ <p>Upload an image and enter a prompt to generate outputs.</p>
246
  </div>
247
  """
248
  )
249
 
250
  with gr.Row():
251
  with gr.Column():
252
+ image_input = gr.Image(
253
+ type="pil",
254
+ label="Upload Image",
255
+ image_mode="RGBA",
256
+ elem_id="image-input"
257
+ )
258
+ gemini_api_key = gr.Textbox(
259
+ lines=1,
260
+ placeholder="Enter Gemini API Key (optional)",
261
+ label="Gemini API Key (optional)"
262
+ )
263
  prompt_input = gr.Textbox(
264
+ lines=2,
265
+ placeholder="Enter prompt here...",
266
+ label="Prompt"
267
  )
268
+ submit_btn = gr.Button("Generate")
 
 
 
 
 
 
269
  with gr.Column():
270
+ output_gallery = gr.Gallery(label="Generated Outputs")
271
+ output_text = gr.Textbox(
272
+ label="Gemini Output",
273
+ placeholder="Text response will appear here if no image is generated."
274
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
 
276
+ gr.Markdown("## Try these examples", elem_classes="gr-examples-header")
 
 
277
 
278
+ examples = [
279
+ ["data/1.webp", 'change text to "AMEER"', ""],
280
+ ["data/2.webp", "remove the spoon from hand only", ""],
281
+ ["data/3.webp", 'change text to "Make it "', ""],
282
+ ["data/1.jpg", "add joker style only on face", ""],
283
+ ["data/1777043.jpg", "add joker style only on face", ""],
284
+ ["data/2807615.jpg", "add lipstick on lip only", ""],
285
+ ["data/76860.jpg", "add lipstick on lip only", ""],
286
+ ["data/2807615.jpg", "make it happy looking face only", ""],
287
+ ]
288
 
289
+ gr.Examples(
290
+ examples=examples,
291
+ inputs=[image_input, prompt_input],
292
+ elem_id="examples-grid"
 
 
 
 
 
 
 
293
  )
294
 
295
+ demo.queue(max_size=50).launch()