Update app.py
Browse files
app.py
CHANGED
@@ -61,12 +61,25 @@ with gr.Blocks(title="Animal Classifier", css=css) as demo:
|
|
61 |
|
62 |
inputs.change(update_state, inputs, all_files_state)
|
63 |
|
64 |
-
# Handle example selection - FIXED
|
65 |
def add_example(example_index, current_files):
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
# Corrected gallery select handler
|
72 |
examples_gallery.select(
|
|
|
61 |
|
62 |
inputs.change(update_state, inputs, all_files_state)
|
63 |
|
64 |
+
# Handle example selection - FIXED WITH VALIDATION
|
65 |
def add_example(example_index, current_files):
|
66 |
+
try:
|
67 |
+
# Handle Gradio's selection format
|
68 |
+
if isinstance(example_index, list):
|
69 |
+
if not example_index: # Empty selection
|
70 |
+
return current_files
|
71 |
+
selected_idx = example_index[0]
|
72 |
+
else:
|
73 |
+
selected_idx = example_index
|
74 |
+
|
75 |
+
# Validate index range
|
76 |
+
if 0 <= selected_idx < len(example_images):
|
77 |
+
selected_path = example_images[selected_idx]
|
78 |
+
return current_files + [selected_path]
|
79 |
+
return current_files
|
80 |
+
except Exception as e:
|
81 |
+
print(f"Error handling example selection: {str(e)}")
|
82 |
+
return current_files
|
83 |
|
84 |
# Corrected gallery select handler
|
85 |
examples_gallery.select(
|