Jacksonnavigator7 commited on
Commit
9a8aba9
·
verified ·
1 Parent(s): 3076d64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -3
app.py CHANGED
@@ -71,7 +71,15 @@ translations = {
71
  }
72
  }
73
 
74
- def clean_bird_name(name):
 
 
 
 
 
 
 
 
75
  """Clean bird name by removing numbers and special characters, and fix formatting"""
76
  # Remove numbers and dots at the beginning
77
  cleaned = re.sub(r'^\d+\.', '', name)
@@ -576,6 +584,21 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
576
  with gr.Row():
577
  with gr.Column(scale=1):
578
  input_image = gr.Image(type="pil", label=translations['en']['upload_label'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579
  submit_btn = gr.Button(translations['en']['identify_button'], variant="primary")
580
 
581
  with gr.Column(scale=2):
@@ -635,6 +658,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
635
  f"# {t['app_title']}",
636
  f"{t['app_description']}",
637
  t['upload_label'],
 
638
  t['identify_button'],
639
  t['predictions_label'],
640
  t['bird_info_label'],
@@ -642,9 +666,25 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
642
  t['question_label'],
643
  t['question_placeholder'],
644
  t['submit_question'],
645
- t['clear_conversation']
 
 
646
  )
647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
648
  # Set up event handlers
649
  language_selector.change(
650
  update_language,
@@ -654,6 +694,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
654
  title_md,
655
  description_md,
656
  input_image,
 
657
  submit_btn,
658
  prediction_output,
659
  bird_info_output,
@@ -661,10 +702,18 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
661
  follow_up_input,
662
  follow_up_input,
663
  follow_up_btn,
664
- clear_btn
 
665
  ]
666
  )
667
 
 
 
 
 
 
 
 
668
  # Add loading state for better UX
669
  submit_btn.click(
670
  lambda x, y: (None, create_message_html(translations[y]['loading'], "⏳", y), "", ""),
 
71
  }
72
  }
73
 
74
+ # Example images configuration
75
+ EXAMPLE_IMAGES = [
76
+ {"path": "image.jpg", "name": "Example Bird 1"},
77
+ {"path": "image1.webp", "name": "Example Bird 2"},
78
+ {"path": "image2.jpg", "name": "Example Bird 3"},
79
+ {"path": "image3.jpg", "name": "Example Bird 4"}
80
+ ]
81
+
82
+ def clean_bird_name(name):
83
  """Clean bird name by removing numbers and special characters, and fix formatting"""
84
  # Remove numbers and dots at the beginning
85
  cleaned = re.sub(r'^\d+\.', '', name)
 
584
  with gr.Row():
585
  with gr.Column(scale=1):
586
  input_image = gr.Image(type="pil", label=translations['en']['upload_label'])
587
+
588
+ # Example images section
589
+ example_header = gr.Markdown(f"### {translations['en']['example_images']}")
590
+
591
+ # Create example image buttons in a grid
592
+ with gr.Row():
593
+ example_buttons = []
594
+ for i, example in enumerate(EXAMPLE_IMAGES):
595
+ btn = gr.Button(
596
+ f"{translations['en']['try_example']} {i+1}",
597
+ variant="secondary",
598
+ size="sm"
599
+ )
600
+ example_buttons.append(btn)
601
+
602
  submit_btn = gr.Button(translations['en']['identify_button'], variant="primary")
603
 
604
  with gr.Column(scale=2):
 
658
  f"# {t['app_title']}",
659
  f"{t['app_description']}",
660
  t['upload_label'],
661
+ f"### {t['example_images']}",
662
  t['identify_button'],
663
  t['predictions_label'],
664
  t['bird_info_label'],
 
666
  t['question_label'],
667
  t['question_placeholder'],
668
  t['submit_question'],
669
+ t['clear_conversation'],
670
+ # Update example button labels
671
+ *[f"{t['try_example']} {i+1}" for i in range(len(EXAMPLE_IMAGES))]
672
  )
673
 
674
+ # Functions to handle example image clicks
675
+ def create_example_handlers():
676
+ """Create handlers for example image buttons"""
677
+ handlers = []
678
+ for example in EXAMPLE_IMAGES:
679
+ def make_handler(path):
680
+ def handler():
681
+ return load_example_image(path)
682
+ return handler
683
+ handlers.append(make_handler(example["path"]))
684
+ return handlers
685
+
686
+ example_handlers = create_example_handlers()
687
+
688
  # Set up event handlers
689
  language_selector.change(
690
  update_language,
 
694
  title_md,
695
  description_md,
696
  input_image,
697
+ example_header,
698
  submit_btn,
699
  prediction_output,
700
  bird_info_output,
 
702
  follow_up_input,
703
  follow_up_input,
704
  follow_up_btn,
705
+ clear_btn,
706
+ *example_buttons
707
  ]
708
  )
709
 
710
+ # Set up example image button handlers
711
+ for i, (btn, handler) in enumerate(zip(example_buttons, example_handlers)):
712
+ btn.click(
713
+ handler,
714
+ outputs=[input_image]
715
+ )
716
+
717
  # Add loading state for better UX
718
  submit_btn.click(
719
  lambda x, y: (None, create_message_html(translations[y]['loading'], "⏳", y), "", ""),