Astridkraft commited on
Commit
98e4d76
·
verified ·
1 Parent(s): 1af4284

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -35
app.py CHANGED
@@ -320,6 +320,15 @@ def handle_text_integration_i2i(original_image, generated_image, text, text_x, t
320
  result = add_text_to_image(target_image, text, text_x, text_y)
321
  return result, output_component
322
 
 
 
 
 
 
 
 
 
 
323
  def main_ui():
324
  with gr.Blocks(
325
  title="AI Image Generator",
@@ -397,6 +406,12 @@ def main_ui():
397
  type="pil"
398
  )
399
 
 
 
 
 
 
 
400
  # EVENT-HANDLER TEXT-zu-BILD
401
  generate_btn.click(
402
  fn=text_to_image,
@@ -405,11 +420,6 @@ def main_ui():
405
  concurrency_limit=1
406
  )
407
 
408
- preview_t2i.select(
409
- fn=set_text_position,
410
- outputs=[text_x_t2i, text_y_t2i]
411
- )
412
-
413
  text_btn_t2i.click(
414
  fn=add_text_to_image,
415
  inputs=[txt_output, text_input_t2i, text_x_t2i, text_y_t2i],
@@ -484,12 +494,16 @@ def main_ui():
484
  show_download_button=True,
485
  type="pil"
486
  )
487
-
488
-
489
-
490
  # TEXT INTEGRATION FÜR BILD-zu-BILD
491
  text_input_i2i, text_x_i2i, text_y_i2i, target_selector, text_btn_i2i = create_text_integration_section_i2i()
492
 
 
 
 
 
 
 
493
  # EVENT-HANDLER BILD-zu-BILD
494
  img_input.change(
495
  fn=process_image_upload,
@@ -511,33 +525,6 @@ def main_ui():
511
  inputs=coordinate_inputs,
512
  outputs=preview_output
513
  )
514
-
515
-
516
- # ALTERNATIVE CLICK-ERKENNUNG
517
- click_x = gr.Number(value=100, visible=False)
518
- click_y = gr.Number(value=100, visible=False)
519
-
520
- def capture_click(image, event):
521
- if event:
522
- print(f"🎯 CLICK ERFOLGREICH: ({event.x}, {event.y})")
523
- return event.x, event.y
524
- print("❌ CLICK FEHLGESCHLAGEN")
525
- return 100, 100
526
-
527
- # Verwende .click() statt .select()
528
- preview_output.click(
529
- fn=capture_click,
530
- inputs=[preview_output],
531
- outputs=[click_x, click_y]
532
- )
533
-
534
- # Ändere die Text-Integration auf click_x, click_y
535
- text_btn_i2i.click(
536
- fn=handle_text_integration_i2i,
537
- inputs=[img_input, img_output, text_input_i2i, click_x, click_y, target_selector],
538
- outputs=[img_input, img_output]
539
- )
540
-
541
 
542
  transform_btn.click(
543
  fn=img_to_image,
 
320
  result = add_text_to_image(target_image, text, text_x, text_y)
321
  return result, output_component
322
 
323
+ # === CLICK HANDLER FÜR BEIDE TABS ===
324
+ def capture_click(event: gr.SelectData):
325
+ """Handhabt Klicks in beiden Tabs"""
326
+ if event and hasattr(event, 'index'):
327
+ print(f"🎯 CLICK ERFOLGREICH: ({event.index[0]}, {event.index[1]})")
328
+ return event.index[0], event.index[1]
329
+ print("❌ CLICK FEHLGESCHLAGEN - Event oder Index fehlt")
330
+ return 100, 100
331
+
332
  def main_ui():
333
  with gr.Blocks(
334
  title="AI Image Generator",
 
406
  type="pil"
407
  )
408
 
409
+ # CLICK HANDLER FÜR TEXT-zu-BILD
410
+ preview_t2i.select(
411
+ fn=capture_click,
412
+ outputs=[text_x_t2i, text_y_t2i]
413
+ )
414
+
415
  # EVENT-HANDLER TEXT-zu-BILD
416
  generate_btn.click(
417
  fn=text_to_image,
 
420
  concurrency_limit=1
421
  )
422
 
 
 
 
 
 
423
  text_btn_t2i.click(
424
  fn=add_text_to_image,
425
  inputs=[txt_output, text_input_t2i, text_x_t2i, text_y_t2i],
 
494
  show_download_button=True,
495
  type="pil"
496
  )
497
+
 
 
498
  # TEXT INTEGRATION FÜR BILD-zu-BILD
499
  text_input_i2i, text_x_i2i, text_y_i2i, target_selector, text_btn_i2i = create_text_integration_section_i2i()
500
 
501
+ # CLICK HANDLER FÜR BILD-zu-BILD
502
+ preview_output.select(
503
+ fn=capture_click,
504
+ outputs=[text_x_i2i, text_y_i2i]
505
+ )
506
+
507
  # EVENT-HANDLER BILD-zu-BILD
508
  img_input.change(
509
  fn=process_image_upload,
 
525
  inputs=coordinate_inputs,
526
  outputs=preview_output
527
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
 
529
  transform_btn.click(
530
  fn=img_to_image,