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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -18,6 +18,15 @@ def classify(image, model_name):
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,21 +36,21 @@ with gr.Blocks() as demo:
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
- # Use an HTML component to update the text color to blue when the model changes.
35
- model_display = gr.HTML("<p style='color:blue;'>gender</p>")
36
- # Update display when state changes.
37
- selected_model.change(lambda m: f"<p style='color:blue;'>{m}</p>", selected_model, model_display)
 
38
 
39
  # Main interface: image input, analyze button, and prediction output.
40
  with gr.Column():
41
  image_input = gr.Image(type="numpy", label="Upload Image")
42
  analyze_btn = gr.Button("Analyze")
43
  output_label = gr.Label(label="Prediction Scores")
44
-
45
  # When the "Analyze" button is clicked, use the selected model to classify the image.
46
  analyze_btn.click(fn=classify, inputs=[image_input, selected_model], outputs=output_label)
47
 
 
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
  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