BATUTO-ART commited on
Commit
5bba165
·
verified ·
1 Parent(s): dfe51cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -44
app.py CHANGED
@@ -97,7 +97,7 @@ class FashionDB:
97
  BACKGROUNDS = {
98
  "sensual": ["luxury boutique hotel room with silk sheets", "intimate bedroom with soft fabrics"],
99
  "editorial": ["minimalist photo studio with concrete backdrop", "urban editorial set"],
100
- "professional": ["glass skcraper boardroom", "modern executive office"],
101
  "artistic": ["urban alley with textured walls", "abstract art gallery space"],
102
  "default": ["neutral indoor environment", "simple professional setting"]
103
  }
@@ -442,27 +442,30 @@ class SuperBot:
442
  return json.dumps(self.projects[project], indent=2, ensure_ascii=False)
443
  return "{}"
444
  # ============================================
445
- # INTERFAZ GRADIO
446
  # ============================================
447
  def create_interface():
448
  """Crea la interfaz de Gradio"""
449
  bot = SuperBot()
450
  assistants_list = list(bot.assistants.keys())
451
 
452
- with gr.Blocks(theme=gr.themes.Soft(), title="BATUTO-ART v5.0") as app:
453
  gr.Markdown("# 🎨 SUPER MULTI-ASISTENTE BATUTO-ART v5.0\n*For BATUTO only*")
454
 
455
  # Selector de asistente
456
- assistant_dropdown = gr.Dropdown(
457
- choices=assistants_list,
458
- value="sara",
459
- label="👤 Select Assistant",
460
- interactive=True
461
- )
 
462
 
 
463
  assistant_dropdown.change(
464
- fn=bot.set_assistant,
465
- inputs=[assistant_dropdown]
 
466
  )
467
 
468
  # Tabs principales
@@ -492,30 +495,42 @@ def create_interface():
492
  with gr.Row():
493
  subject_input = gr.Textbox(
494
  label="Subject",
495
- placeholder="Describe the model or scene..."
 
496
  )
497
  mode_radio = gr.Radio(
498
  choices=["soft", "intense", "editorial"],
499
  value="intense",
500
- label="Mode"
 
501
  )
502
 
503
  prompt_output = gr.Textbox(
504
  label="Generated Prompt",
505
  lines=12,
506
- show_copy_button=True,
507
  interactive=False
508
  )
509
 
510
  def generate_prompt(subject, mode):
 
 
511
  assistant = bot.assistants[bot.current_assistant]
512
  return assistant.generate_prompt(subject, mode)
513
 
514
- gr.Button("Generate Prompt", variant="primary").click(
 
515
  fn=generate_prompt,
516
  inputs=[subject_input, mode_radio],
517
  outputs=prompt_output
518
  )
 
 
 
 
 
 
 
 
519
 
520
  # Tab: Image Studio
521
  with gr.Tab("🖼️ Image Studio"):
@@ -546,10 +561,11 @@ def create_interface():
546
  gallery_output = gr.Gallery(
547
  label="Generated Images",
548
  columns=2,
549
- height=400,
550
- object_fit="contain"
551
  )
552
 
 
 
553
  def generate_images(prompt, num_images, ratio):
554
  if not prompt.strip():
555
  return [], "❌ Please enter a prompt"
@@ -564,8 +580,6 @@ def create_interface():
564
  return images, f"✅ Generated {len(images)} images"
565
  return [], "❌ Error generating images"
566
 
567
- status_text = gr.Markdown()
568
-
569
  generate_btn.click(
570
  fn=generate_images,
571
  inputs=[prompt_input, num_images_slider, ratio_select],
@@ -574,18 +588,24 @@ def create_interface():
574
 
575
  # Tab: Analyzer
576
  with gr.Tab("🔍 Analyzer"):
577
- image_upload = gr.Image(
578
- type="filepath",
579
- label="Upload Image"
580
- )
581
- analysis_output = gr.Textbox(
582
- label="Analysis Result",
583
- lines=6,
584
- interactive=False
585
- )
 
 
 
 
 
586
 
587
- gr.Button("Analyze Image").click(
588
- fn=bot.assistants["maya"].analyze_image,
 
589
  inputs=[image_upload],
590
  outputs=analysis_output
591
  )
@@ -617,7 +637,8 @@ def create_interface():
617
  lines=12,
618
  interactive=False
619
  )
620
- gr.Button("Export Project").click(
 
621
  fn=bot.export_project,
622
  inputs=[project_name],
623
  outputs=export_output
@@ -630,7 +651,7 @@ def create_interface():
630
  )
631
 
632
  add_asset_btn.click(
633
- fn=bot.add_asset,
634
  inputs=[project_name, asset_type, asset_content],
635
  outputs=project_status
636
  )
@@ -640,17 +661,23 @@ def create_interface():
640
  gallery_data = load_json("data/gallery.json", [])
641
  gallery_images = []
642
 
643
- for item in gallery_data[-20:]: # Últimas 20 imágenes
644
- if "path" in item and os.path.exists(item["path"]):
645
- gallery_images.append(item["path"])
 
 
 
 
646
 
647
- gr.Gallery(
648
- value=gallery_images,
649
- label="Gallery History",
650
- columns=4,
651
- height=500,
652
- object_fit="cover"
653
- )
 
 
654
 
655
  return app
656
 
@@ -671,6 +698,7 @@ if __name__ == "__main__":
671
  server_name="0.0.0.0",
672
  server_port=7860,
673
  share=False,
674
- debug=False,
675
- show_error=True
 
676
  )
 
97
  BACKGROUNDS = {
98
  "sensual": ["luxury boutique hotel room with silk sheets", "intimate bedroom with soft fabrics"],
99
  "editorial": ["minimalist photo studio with concrete backdrop", "urban editorial set"],
100
+ "professional": ["glass skyscraper boardroom", "modern executive office"],
101
  "artistic": ["urban alley with textured walls", "abstract art gallery space"],
102
  "default": ["neutral indoor environment", "simple professional setting"]
103
  }
 
442
  return json.dumps(self.projects[project], indent=2, ensure_ascii=False)
443
  return "{}"
444
  # ============================================
445
+ # INTERFAZ GRADIO - COMPATIBLE CON GRADIO 6.0
446
  # ============================================
447
  def create_interface():
448
  """Crea la interfaz de Gradio"""
449
  bot = SuperBot()
450
  assistants_list = list(bot.assistants.keys())
451
 
452
+ with gr.Blocks(title="BATUTO-ART v5.0") as app:
453
  gr.Markdown("# 🎨 SUPER MULTI-ASISTENTE BATUTO-ART v5.0\n*For BATUTO only*")
454
 
455
  # Selector de asistente
456
+ with gr.Row():
457
+ assistant_dropdown = gr.Dropdown(
458
+ choices=assistants_list,
459
+ value="sara",
460
+ label="👤 Select Assistant",
461
+ interactive=True
462
+ )
463
 
464
+ # Callback para cambiar asistente
465
  assistant_dropdown.change(
466
+ fn=lambda x: bot.set_assistant(x) or f"Asistente cambiado a: {x}",
467
+ inputs=[assistant_dropdown],
468
+ outputs=None
469
  )
470
 
471
  # Tabs principales
 
495
  with gr.Row():
496
  subject_input = gr.Textbox(
497
  label="Subject",
498
+ placeholder="Describe the model or scene...",
499
+ scale=2
500
  )
501
  mode_radio = gr.Radio(
502
  choices=["soft", "intense", "editorial"],
503
  value="intense",
504
+ label="Mode",
505
+ scale=1
506
  )
507
 
508
  prompt_output = gr.Textbox(
509
  label="Generated Prompt",
510
  lines=12,
 
511
  interactive=False
512
  )
513
 
514
  def generate_prompt(subject, mode):
515
+ if not subject:
516
+ return "⚠️ Please enter a subject"
517
  assistant = bot.assistants[bot.current_assistant]
518
  return assistant.generate_prompt(subject, mode)
519
 
520
+ generate_btn = gr.Button("Generate Prompt", variant="primary")
521
+ generate_btn.click(
522
  fn=generate_prompt,
523
  inputs=[subject_input, mode_radio],
524
  outputs=prompt_output
525
  )
526
+
527
+ # Botón para copiar
528
+ copy_btn = gr.Button("📋 Copy to Clipboard", variant="secondary")
529
+ copy_btn.click(
530
+ fn=lambda x: gr.update(value=x),
531
+ inputs=[prompt_output],
532
+ outputs=None
533
+ )
534
 
535
  # Tab: Image Studio
536
  with gr.Tab("🖼️ Image Studio"):
 
561
  gallery_output = gr.Gallery(
562
  label="Generated Images",
563
  columns=2,
564
+ height=400
 
565
  )
566
 
567
+ status_text = gr.Markdown()
568
+
569
  def generate_images(prompt, num_images, ratio):
570
  if not prompt.strip():
571
  return [], "❌ Please enter a prompt"
 
580
  return images, f"✅ Generated {len(images)} images"
581
  return [], "❌ Error generating images"
582
 
 
 
583
  generate_btn.click(
584
  fn=generate_images,
585
  inputs=[prompt_input, num_images_slider, ratio_select],
 
588
 
589
  # Tab: Analyzer
590
  with gr.Tab("🔍 Analyzer"):
591
+ with gr.Row():
592
+ image_upload = gr.Image(
593
+ type="filepath",
594
+ label="Upload Image",
595
+ height=300
596
+ )
597
+ analysis_output = gr.Textbox(
598
+ label="Analysis Result",
599
+ lines=6,
600
+ interactive=False
601
+ )
602
+
603
+ def analyze_image_wrapper(image_path):
604
+ return bot.assistants["maya"].analyze_image(image_path)
605
 
606
+ analyze_btn = gr.Button("Analyze Image", variant="primary")
607
+ analyze_btn.click(
608
+ fn=analyze_image_wrapper,
609
  inputs=[image_upload],
610
  outputs=analysis_output
611
  )
 
637
  lines=12,
638
  interactive=False
639
  )
640
+ export_btn = gr.Button("Export Project")
641
+ export_btn.click(
642
  fn=bot.export_project,
643
  inputs=[project_name],
644
  outputs=export_output
 
651
  )
652
 
653
  add_asset_btn.click(
654
+ fn=lambda p, t, c: bot.add_asset(p, t, c) or "✅ Asset added successfully",
655
  inputs=[project_name, asset_type, asset_content],
656
  outputs=project_status
657
  )
 
661
  gallery_data = load_json("data/gallery.json", [])
662
  gallery_images = []
663
 
664
+ for item in gallery_data[-20:]: # Últimas 20 entradas
665
+ if isinstance(item, dict):
666
+ # Intentar diferentes formatos de guardado
667
+ if "path" in item and os.path.exists(item["path"]):
668
+ gallery_images.append(item["path"])
669
+ elif "url" in item:
670
+ gallery_images.append(item["url"])
671
 
672
+ if gallery_images:
673
+ gr.Gallery(
674
+ value=gallery_images,
675
+ label="Gallery History",
676
+ columns=4,
677
+ height=500
678
+ )
679
+ else:
680
+ gr.Markdown("No images in gallery yet. Generate some images first!")
681
 
682
  return app
683
 
 
698
  server_name="0.0.0.0",
699
  server_port=7860,
700
  share=False,
701
+ debug=True,
702
+ show_error=True,
703
+ theme=gr.themes.Soft()
704
  )