Update app.py
Browse files
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 |
-
|
|
|
239 |
with gr.Blocks() as demo:
|
240 |
gr.HTML(
|
241 |
"""
|
242 |
<div style="text-align: center; margin-bottom: 1rem;">
|
243 |
-
<h1
|
244 |
-
<p
|
245 |
</div>
|
246 |
"""
|
247 |
)
|
248 |
|
249 |
with gr.Row():
|
250 |
with gr.Column():
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
prompt_input = gr.Textbox(
|
256 |
-
lines=
|
257 |
-
placeholder="
|
258 |
-
label="
|
259 |
)
|
260 |
-
|
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 |
-
|
269 |
-
output_text = gr.Textbox(
|
270 |
-
|
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 |
-
|
306 |
-
example1_btn = gr.Button("์์ 1 ์คํ")
|
307 |
-
example2_btn = gr.Button("์์ 2 ์คํ")
|
308 |
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
|
320 |
-
gr.
|
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 |
-
|
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()
|
|