ginipick commited on
Commit
6549221
Β·
verified Β·
1 Parent(s): 227d8c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -86
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
- # 6. Gradio UI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- # 6 example prompts (slightly more colorful list)
372
- examples = [
373
- [
374
- "Futuristic neon sign with <text1>, plus near the bottom",
375
- "OPEN", "", ""
376
- ],
377
- [
378
- "On a grand stage, <text1> in big letters and on the left side",
379
- "ν™˜μ˜ν•©λ‹ˆλ‹€.", "", ""
380
- ],
381
- [
382
- "A classical poster reading <text1> in bold, as a subtitle",
383
- "错觉", "", ""
384
- ],
385
- [
386
- "In a cartoon style, a speech bubble with <text1> and another text ",
387
- "μ•ˆλ…•", "", ""
388
- ],
389
- [
390
- "Large billboard featuring <text1>",
391
- "μ•„λ¦„λ‹€μš΄ λ‹Ήμ‹ ", "", ""
392
- ],
393
- [
394
- "μ¬κΈ€λΌμŠ€ μ°©μš©ν•œ 흰색 κ³ μ–‘μ΄μ˜ λ°°λ„ˆ <text1>",
395
- "μ•ˆλ…•", "", ""
396
- ],
397
- ]
398
-
399
- with gr.Row():
400
- with gr.Column():
401
- with gr.Group():
402
- prompt_input = gr.Textbox(
403
- lines=3,
404
- label="Prompt (Korean or English)",
405
- placeholder="On a grand stage, <text1> in big letters..."
406
- )
407
- final_text1 = gr.Textbox(
408
- label="New Text #1 (Required)",
409
- placeholder="Example: HELLO or μ•ˆλ…•ν•˜μ„Έμš”"
410
- )
411
- final_text2 = gr.Textbox(
412
- label="New Text #2 (Optional)",
413
- placeholder="Example: WORLD or λ°˜κ°‘μŠ΅λ‹ˆλ‹€"
414
- )
415
- final_text3 = gr.Textbox(
416
- label="New Text #3 (Optional)",
417
- placeholder="(Leave blank if not used)"
418
- )
419
-
420
- with gr.Accordion("Advanced Settings (optional)", open=False):
421
- height = gr.Slider(label="Height", minimum=256, maximum=1152, step=64, value=512)
422
- width = gr.Slider(label="Width", minimum=256, maximum=1152, step=64, value=512)
423
- steps = gr.Slider(label="Inference Steps", minimum=6, maximum=25, step=1, value=8)
424
- scale = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=10.0, step=0.5, value=3.5)
425
- seed = gr.Number(label="Seed", value=1234, precision=0)
426
-
427
- run_btn = gr.Button("Generate 2 Final Images", variant="primary")
428
-
429
- # Show the examples
430
- gr.Examples(
431
- examples=examples,
432
- inputs=[prompt_input, final_text1, final_text2, final_text3],
433
- label="Example Prompts"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)