Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -269,7 +269,7 @@ def change_text_in_image_two_times(original_image, instruction):
|
|
269 |
|
270 |
|
271 |
#######################################
|
272 |
-
# 5. Main Process
|
273 |
#######################################
|
274 |
|
275 |
def run_process(
|
@@ -313,7 +313,27 @@ def run_process(
|
|
313 |
return [final_imgs[0], final_imgs[1]]
|
314 |
|
315 |
#######################################
|
316 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
#######################################
|
318 |
|
319 |
with gr.Blocks(title="Eevery Text Imaginator: FLUX") as demo:
|
@@ -367,90 +387,113 @@ with gr.Blocks(title="Eevery Text Imaginator: FLUX") as demo:
|
|
367 |
<hr style="margin: 15px 0;">
|
368 |
"""
|
369 |
)
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
)
|
435 |
-
|
436 |
-
with gr.Column():
|
437 |
-
final_image_output1 = gr.Image(label="Final Image #1", type="pil")
|
438 |
-
final_image_output2 = gr.Image(label="Final Image #2", type="pil")
|
439 |
-
|
440 |
-
run_btn.click(
|
441 |
-
fn=run_process,
|
442 |
-
inputs=[
|
443 |
-
prompt_input,
|
444 |
-
final_text1,
|
445 |
-
final_text2,
|
446 |
-
final_text3,
|
447 |
-
height,
|
448 |
-
width,
|
449 |
-
steps,
|
450 |
-
scale,
|
451 |
-
seed
|
452 |
-
],
|
453 |
-
outputs=[final_image_output1, final_image_output2]
|
454 |
-
)
|
455 |
|
456 |
demo.launch(max_threads=20)
|
|
|
269 |
|
270 |
|
271 |
#######################################
|
272 |
+
# 5. Main Process (Generation from Prompt)
|
273 |
#######################################
|
274 |
|
275 |
def run_process(
|
|
|
313 |
return [final_imgs[0], final_imgs[1]]
|
314 |
|
315 |
#######################################
|
316 |
+
# 5-2. Process for Editing Uploaded Image
|
317 |
+
#######################################
|
318 |
+
|
319 |
+
def run_edit_process(input_image, final_text1, final_text2, final_text3):
|
320 |
+
"""
|
321 |
+
Process for editing an uploaded image.
|
322 |
+
1) For each provided text, if it's purely English, use as-is;
|
323 |
+
otherwise, replace with random letters.
|
324 |
+
2) Build instructions and call the text modification function twice.
|
325 |
+
"""
|
326 |
+
r1 = maybe_use_random_or_original(final_text1)
|
327 |
+
r2 = maybe_use_random_or_original(final_text2)
|
328 |
+
r3 = maybe_use_random_or_original(final_text3)
|
329 |
+
print(f"[DEBUG] Editing image with placeholders: r1='{r1}', r2='{r2}', r3='{r3}'")
|
330 |
+
instruction = build_multi_change_instruction(r1, final_text1, r2, final_text2, r3, final_text3)
|
331 |
+
print(f"[DEBUG] Editing instruction: {instruction}")
|
332 |
+
final_imgs = change_text_in_image_two_times(input_image, instruction)
|
333 |
+
return [final_imgs[0], final_imgs[1]]
|
334 |
+
|
335 |
+
#######################################
|
336 |
+
# 6. Gradio UI with Two Tabs
|
337 |
#######################################
|
338 |
|
339 |
with gr.Blocks(title="Eevery Text Imaginator: FLUX") as demo:
|
|
|
387 |
<hr style="margin: 15px 0;">
|
388 |
"""
|
389 |
)
|
390 |
+
|
391 |
+
with gr.Tabs():
|
392 |
+
with gr.TabItem("Generate from Prompt"):
|
393 |
+
with gr.Row():
|
394 |
+
with gr.Column():
|
395 |
+
with gr.Group():
|
396 |
+
prompt_input = gr.Textbox(
|
397 |
+
lines=3,
|
398 |
+
label="Prompt (Korean or English)",
|
399 |
+
placeholder="On a grand stage, <text1> in big letters..."
|
400 |
+
)
|
401 |
+
final_text1 = gr.Textbox(
|
402 |
+
label="New Text #1 (Required)",
|
403 |
+
placeholder="Example: HELLO or μλ
νμΈμ"
|
404 |
+
)
|
405 |
+
final_text2 = gr.Textbox(
|
406 |
+
label="New Text #2 (Optional)",
|
407 |
+
placeholder="Example: WORLD or λ°κ°μ΅λλ€"
|
408 |
+
)
|
409 |
+
final_text3 = gr.Textbox(
|
410 |
+
label="New Text #3 (Optional)",
|
411 |
+
placeholder="(Leave blank if not used)"
|
412 |
+
)
|
413 |
+
with gr.Accordion("Advanced Settings (optional)", open=False):
|
414 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1152, step=64, value=512)
|
415 |
+
width = gr.Slider(label="Width", minimum=256, maximum=1152, step=64, value=512)
|
416 |
+
steps = gr.Slider(label="Inference Steps", minimum=6, maximum=25, step=1, value=8)
|
417 |
+
scale = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=10.0, step=0.5, value=3.5)
|
418 |
+
seed = gr.Number(label="Seed", value=1234, precision=0)
|
419 |
+
run_btn = gr.Button("Generate 2 Final Images", variant="primary")
|
420 |
+
gr.Examples(
|
421 |
+
examples=[
|
422 |
+
[
|
423 |
+
"Futuristic neon sign with <text1>, plus near the bottom",
|
424 |
+
"OPEN", "", ""
|
425 |
+
],
|
426 |
+
[
|
427 |
+
"On a grand stage, <text1> in big letters and on the left side",
|
428 |
+
"νμν©λλ€.", "", ""
|
429 |
+
],
|
430 |
+
[
|
431 |
+
"A classical poster reading <text1> in bold, as a subtitle",
|
432 |
+
"ιθ§", "", ""
|
433 |
+
],
|
434 |
+
[
|
435 |
+
"In a cartoon style, a speech bubble with <text1> and another text ",
|
436 |
+
"μλ
", "", ""
|
437 |
+
],
|
438 |
+
[
|
439 |
+
"Large billboard featuring <text1>",
|
440 |
+
"μλ¦λ€μ΄ λΉμ ", "", ""
|
441 |
+
],
|
442 |
+
[
|
443 |
+
"μ¬κΈλΌμ€ μ°©μ©ν ν°μ κ³ μμ΄μ λ°°λ <text1>",
|
444 |
+
"μλ
", "", ""
|
445 |
+
],
|
446 |
+
],
|
447 |
+
inputs=[prompt_input, final_text1, final_text2, final_text3],
|
448 |
+
label="Example Prompts"
|
449 |
+
)
|
450 |
+
with gr.Column():
|
451 |
+
final_image_output1 = gr.Image(label="Final Image #1", type="pil")
|
452 |
+
final_image_output2 = gr.Image(label="Final Image #2", type="pil")
|
453 |
+
run_btn.click(
|
454 |
+
fn=run_process,
|
455 |
+
inputs=[
|
456 |
+
prompt_input,
|
457 |
+
final_text1,
|
458 |
+
final_text2,
|
459 |
+
final_text3,
|
460 |
+
height,
|
461 |
+
width,
|
462 |
+
steps,
|
463 |
+
scale,
|
464 |
+
seed
|
465 |
+
],
|
466 |
+
outputs=[final_image_output1, final_image_output2]
|
467 |
+
)
|
468 |
+
|
469 |
+
with gr.TabItem("Edit Uploaded Image"):
|
470 |
+
with gr.Row():
|
471 |
+
with gr.Column():
|
472 |
+
uploaded_image = gr.Image(
|
473 |
+
label="Upload Image for Editing",
|
474 |
+
type="pil",
|
475 |
+
source="upload"
|
476 |
+
)
|
477 |
+
final_text1_edit = gr.Textbox(
|
478 |
+
label="New Text #1 (Required)",
|
479 |
+
placeholder="Example: HELLO or μλ
νμΈμ"
|
480 |
+
)
|
481 |
+
final_text2_edit = gr.Textbox(
|
482 |
+
label="New Text #2 (Optional)",
|
483 |
+
placeholder="Example: WORLD or λ°κ°μ΅λλ€"
|
484 |
+
)
|
485 |
+
final_text3_edit = gr.Textbox(
|
486 |
+
label="New Text #3 (Optional)",
|
487 |
+
placeholder="(Leave blank if not used)"
|
488 |
+
)
|
489 |
+
run_edit_btn = gr.Button("Edit Image", variant="primary")
|
490 |
+
with gr.Column():
|
491 |
+
edited_image_output1 = gr.Image(label="Edited Image #1", type="pil")
|
492 |
+
edited_image_output2 = gr.Image(label="Edited Image #2", type="pil")
|
493 |
+
run_edit_btn.click(
|
494 |
+
fn=run_edit_process,
|
495 |
+
inputs=[uploaded_image, final_text1_edit, final_text2_edit, final_text3_edit],
|
496 |
+
outputs=[edited_image_output1, edited_image_output2]
|
497 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
|
499 |
demo.launch(max_threads=20)
|