prithivMLmods commited on
Commit
08d30fe
·
verified ·
1 Parent(s): 8574300

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -42
app.py CHANGED
@@ -7,28 +7,6 @@ from gym_workout_classification import workout_classification
7
  from augmented_waste_classifier import waste_classification
8
  from age_classification import age_classification
9
 
10
- # Functions to update the model state when a button is clicked.
11
- def select_gender():
12
- return "gender"
13
-
14
- def select_emotion():
15
- return "emotion"
16
-
17
- def select_dog_breed():
18
- return "dog breed"
19
-
20
- def select_deepfake():
21
- return "deepfake"
22
-
23
- def select_gym_workout():
24
- return "gym workout"
25
-
26
- def select_waste():
27
- return "waste"
28
-
29
- def select_age():
30
- return "age"
31
-
32
  # Main classification function that calls the appropriate model based on selection.
33
  def classify(image, model_name):
34
  if model_name == "gender":
@@ -48,44 +26,79 @@ def classify(image, model_name):
48
  else:
49
  return {"Error": "No model selected"}
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  with gr.Blocks() as demo:
52
  # Sidebar with title and model selection buttons.
53
  with gr.Sidebar():
54
  gr.Markdown("# SigLIP2 224")
55
  with gr.Row():
56
- age_btn = gr.Button("Age Classification")
57
- gender_btn = gr.Button("Gender Classification")
58
- emotion_btn = gr.Button("Emotion Classification")
59
- dog_breed_btn = gr.Button("Dog Breed Classification")
60
- deepfake_btn = gr.Button("Deepfake vs Real")
61
- gym_workout_btn = gr.Button("Gym Workout Classification")
62
- waste_btn = gr.Button("Waste Classification")
 
63
 
64
  # State to hold the current model choice.
65
  selected_model = gr.State("age")
66
 
67
- # Set model state when buttons are clicked.
68
- gender_btn.click(fn=select_gender, inputs=[], outputs=selected_model)
69
- emotion_btn.click(fn=select_emotion, inputs=[], outputs=selected_model)
70
- dog_breed_btn.click(fn=select_dog_breed, inputs=[], outputs=selected_model)
71
- deepfake_btn.click(fn=select_deepfake, inputs=[], outputs=selected_model)
72
- gym_workout_btn.click(fn=select_gym_workout, inputs=[], outputs=selected_model)
73
- waste_btn.click(fn=select_waste, inputs=[], outputs=selected_model)
74
- age_btn.click(fn=select_age, inputs=[], outputs=selected_model)
75
-
76
  gr.Markdown("### Current Model:")
77
  model_display = gr.Textbox(value="age", interactive=False)
78
  # Update display when state changes.
79
  selected_model.change(lambda m: m, selected_model, model_display)
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  # Main interface: image input, analyze button, and prediction output.
82
  with gr.Column():
83
  image_input = gr.Image(type="numpy", label="Upload Image")
84
  analyze_btn = gr.Button("Classify / Predict")
85
- with gr.Column(scale=2):
86
- output_label = gr.Label(label="Prediction Scores")
87
-
88
  # When the "Analyze" button is clicked, use the selected model to classify the image.
89
  analyze_btn.click(fn=classify, inputs=[image_input, selected_model], outputs=output_label)
90
 
91
- demo.launch()
 
7
  from augmented_waste_classifier import waste_classification
8
  from age_classification import age_classification
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Main classification function that calls the appropriate model based on selection.
11
  def classify(image, model_name):
12
  if model_name == "gender":
 
26
  else:
27
  return {"Error": "No model selected"}
28
 
29
+ # Function to update the selected model and button styles.
30
+ def select_model(model_name):
31
+ # Set each button's variant to "primary" if selected, otherwise "secondary"
32
+ gender_variant = "primary" if model_name == "gender" else "secondary"
33
+ emotion_variant = "primary" if model_name == "emotion" else "secondary"
34
+ dog_breed_variant = "primary" if model_name == "dog breed" else "secondary"
35
+ deepfake_variant = "primary" if model_name == "deepfake" else "secondary"
36
+ gym_workout_variant = "primary" if model_name == "gym workout" else "secondary"
37
+ waste_variant = "primary" if model_name == "waste" else "secondary"
38
+ age_variant = "primary" if model_name == "age" else "secondary"
39
+ # Return new state and update objects for each button in the specified order.
40
+ return (
41
+ model_name,
42
+ gr.update(variant=gender_variant),
43
+ gr.update(variant=emotion_variant),
44
+ gr.update(variant=dog_breed_variant),
45
+ gr.update(variant=deepfake_variant),
46
+ gr.update(variant=gym_workout_variant),
47
+ gr.update(variant=waste_variant),
48
+ gr.update(variant=age_variant)
49
+ )
50
+
51
  with gr.Blocks() as demo:
52
  # Sidebar with title and model selection buttons.
53
  with gr.Sidebar():
54
  gr.Markdown("# SigLIP2 224")
55
  with gr.Row():
56
+ # Initialize buttons with variants. Default is "age" set to primary.
57
+ age_btn = gr.Button("Age Classification", variant="primary")
58
+ gender_btn = gr.Button("Gender Classification", variant="secondary")
59
+ emotion_btn = gr.Button("Emotion Classification", variant="secondary")
60
+ dog_breed_btn = gr.Button("Dog Breed Classification", variant="secondary")
61
+ deepfake_btn = gr.Button("Deepfake vs Real", variant="secondary")
62
+ gym_workout_btn = gr.Button("Gym Workout Classification", variant="secondary")
63
+ waste_btn = gr.Button("Waste Classification", variant="secondary")
64
 
65
  # State to hold the current model choice.
66
  selected_model = gr.State("age")
67
 
 
 
 
 
 
 
 
 
 
68
  gr.Markdown("### Current Model:")
69
  model_display = gr.Textbox(value="age", interactive=False)
70
  # Update display when state changes.
71
  selected_model.change(lambda m: m, selected_model, model_display)
72
 
73
+ # Set up click events for each button, updating state and button variants.
74
+ gender_btn.click(fn=lambda: select_model("gender"),
75
+ inputs=[],
76
+ outputs=[selected_model, gender_btn, emotion_btn, dog_breed_btn, deepfake_btn, gym_workout_btn, waste_btn, age_btn])
77
+ emotion_btn.click(fn=lambda: select_model("emotion"),
78
+ inputs=[],
79
+ outputs=[selected_model, gender_btn, emotion_btn, dog_breed_btn, deepfake_btn, gym_workout_btn, waste_btn, age_btn])
80
+ dog_breed_btn.click(fn=lambda: select_model("dog breed"),
81
+ inputs=[],
82
+ outputs=[selected_model, gender_btn, emotion_btn, dog_breed_btn, deepfake_btn, gym_workout_btn, waste_btn, age_btn])
83
+ deepfake_btn.click(fn=lambda: select_model("deepfake"),
84
+ inputs=[],
85
+ outputs=[selected_model, gender_btn, emotion_btn, dog_breed_btn, deepfake_btn, gym_workout_btn, waste_btn, age_btn])
86
+ gym_workout_btn.click(fn=lambda: select_model("gym workout"),
87
+ inputs=[],
88
+ outputs=[selected_model, gender_btn, emotion_btn, dog_breed_btn, deepfake_btn, gym_workout_btn, waste_btn, age_btn])
89
+ waste_btn.click(fn=lambda: select_model("waste"),
90
+ inputs=[],
91
+ outputs=[selected_model, gender_btn, emotion_btn, dog_breed_btn, deepfake_btn, gym_workout_btn, waste_btn, age_btn])
92
+ age_btn.click(fn=lambda: select_model("age"),
93
+ inputs=[],
94
+ outputs=[selected_model, gender_btn, emotion_btn, dog_breed_btn, deepfake_btn, gym_workout_btn, waste_btn, age_btn])
95
+
96
  # Main interface: image input, analyze button, and prediction output.
97
  with gr.Column():
98
  image_input = gr.Image(type="numpy", label="Upload Image")
99
  analyze_btn = gr.Button("Classify / Predict")
100
+ output_label = gr.Label(label="Prediction Scores")
 
 
101
  # When the "Analyze" button is clicked, use the selected model to classify the image.
102
  analyze_btn.click(fn=classify, inputs=[image_input, selected_model], outputs=output_label)
103
 
104
+ demo.launch()