prithivMLmods commited on
Commit
e128767
·
verified ·
1 Parent(s): d2ca184

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -13
app.py CHANGED
@@ -18,15 +18,6 @@ def classify(image, model_name):
18
  else:
19
  return {"Error": "No model selected"}
20
 
21
- # Function to update button styles based on the selected model.
22
- def update_button_styles(selected):
23
- if selected == "gender":
24
- # Set gender button to red (using the "stop" variant) and emotion button to primary.
25
- return gr.Button.update(variant="stop"), gr.Button.update(variant="primary")
26
- else:
27
- # Set emotion button to red and gender button to primary.
28
- return gr.Button.update(variant="primary"), gr.Button.update(variant="stop")
29
-
30
  with gr.Blocks() as demo:
31
  # Sidebar with title and model selection buttons.
32
  with gr.Sidebar():
@@ -36,21 +27,20 @@ with gr.Blocks() as demo:
36
  emotion_btn = gr.Button("Emotion Classification")
37
  # State to hold the current model choice.
38
  selected_model = gr.State("gender")
39
- # Update model state on button clicks.
40
  gender_btn.click(fn=select_gender, inputs=[], outputs=selected_model)
41
  emotion_btn.click(fn=select_emotion, inputs=[], outputs=selected_model)
42
  gr.Markdown("### Current Model:")
43
  model_display = gr.Textbox(value="gender", interactive=False)
44
- # Update model display when state changes.
45
  selected_model.change(lambda m: m, selected_model, model_display)
46
- # Update the button styles based on selection.
47
- selected_model.change(fn=update_button_styles, inputs=selected_model, outputs=[gender_btn, emotion_btn])
48
 
49
  # Main interface: image input, analyze button, and prediction output.
50
  with gr.Column():
51
  image_input = gr.Image(type="numpy", label="Upload Image")
52
  analyze_btn = gr.Button("Analyze")
53
  output_label = gr.Label(label="Prediction Scores")
 
54
  # When the "Analyze" button is clicked, use the selected model to classify the image.
55
  analyze_btn.click(fn=classify, inputs=[image_input, selected_model], outputs=output_label)
56
 
 
18
  else:
19
  return {"Error": "No model selected"}
20
 
 
 
 
 
 
 
 
 
 
21
  with gr.Blocks() as demo:
22
  # Sidebar with title and model selection buttons.
23
  with gr.Sidebar():
 
27
  emotion_btn = gr.Button("Emotion Classification")
28
  # State to hold the current model choice.
29
  selected_model = gr.State("gender")
30
+ # Set model state when buttons are clicked.
31
  gender_btn.click(fn=select_gender, inputs=[], outputs=selected_model)
32
  emotion_btn.click(fn=select_emotion, inputs=[], outputs=selected_model)
33
  gr.Markdown("### Current Model:")
34
  model_display = gr.Textbox(value="gender", interactive=False)
35
+ # Update display when state changes.
36
  selected_model.change(lambda m: m, selected_model, model_display)
 
 
37
 
38
  # Main interface: image input, analyze button, and prediction output.
39
  with gr.Column():
40
  image_input = gr.Image(type="numpy", label="Upload Image")
41
  analyze_btn = gr.Button("Analyze")
42
  output_label = gr.Label(label="Prediction Scores")
43
+
44
  # When the "Analyze" button is clicked, use the selected model to classify the image.
45
  analyze_btn.click(fn=classify, inputs=[image_input, selected_model], outputs=output_label)
46