andrewzamp commited on
Commit
5c16577
·
1 Parent(s): ee9c769

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -135,28 +135,30 @@ def make_prediction(image, choose_resolution, taxonomic_level):
135
  else:
136
  return make_prediction_auto(image)
137
 
138
- # Define the Gradio interface
139
- interface = gr.Interface(
140
- fn=make_prediction,
141
- inputs=[
142
- gr.Image(type="pil"),
143
- gr.Radio(choices=["Yes, I want to specify the taxonomic level", "No, I will let the model decide"],
144
- label="Do you want to choose the taxonomic resolution for predictions?", value="No, I will let the model decide"),
145
- gr.Dropdown(choices=taxonomic_levels, label="Taxonomic level", value="species", interactive=True)],
146
- outputs="html",
147
- title="Amazon arboreal species classification",
148
- description="Upload an image and select the taxonomic level (optional) to classify the species."
149
- )
150
-
151
- # Add custom logic to disable the "Taxonomic level" dropdown when "No, I will let the model decide" is selected
152
  def update_taxonomic_level_interface(choose_resolution):
153
  if choose_resolution == "No, I will let the model decide":
154
  return gr.Dropdown.update(interactive=False)
155
  else:
156
  return gr.Dropdown.update(interactive=True)
157
 
158
- # Set up dynamic behavior for the interface
159
- interface.update(inputs=["Do you want to choose the taxonomic resolution for predictions?"], fn=update_taxonomic_level_interface)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  # Launch the Gradio interface
162
  interface.launch()
 
135
  else:
136
  return make_prediction_auto(image)
137
 
138
+ # Function to dynamically disable/enable the taxonomic level dropdown
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  def update_taxonomic_level_interface(choose_resolution):
140
  if choose_resolution == "No, I will let the model decide":
141
  return gr.Dropdown.update(interactive=False)
142
  else:
143
  return gr.Dropdown.update(interactive=True)
144
 
145
+ # Define the Gradio interface
146
+ with gr.Blocks() as interface:
147
+ with gr.Row():
148
+ image_input = gr.Image(type="pil")
149
+ choose_resolution = gr.Radio(
150
+ choices=["Yes, I want to specify the taxonomic level", "No, I will let the model decide"],
151
+ label="Do you want to choose the taxonomic resolution for predictions?", value="No, I will let the model decide"
152
+ )
153
+ taxonomic_level = gr.Dropdown(
154
+ choices=taxonomic_levels, label="Taxonomic level", value="species", interactive=True
155
+ )
156
+
157
+ result_output = gr.HTML()
158
+
159
+ # Bind the prediction function to the inputs
160
+ choose_resolution.change(fn=update_taxonomic_level_interface, inputs=choose_resolution, outputs=taxonomic_level)
161
+ image_input.submit(fn=make_prediction, inputs=[image_input, choose_resolution, taxonomic_level], outputs=result_output)
162
 
163
  # Launch the Gradio interface
164
  interface.launch()