prithivMLmods commited on
Commit
5e302e0
·
verified ·
1 Parent(s): 85aea3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -50
app.py CHANGED
@@ -6,6 +6,7 @@ from deepfake_vs_real import deepfake_classification
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
  # Main classification function that calls the appropriate model based on selection.
11
  def classify(image, model_name):
@@ -23,37 +24,24 @@ def classify(image, model_name):
23
  return waste_classification(image)
24
  elif model_name == "age":
25
  return age_classification(image)
 
 
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")
@@ -61,44 +49,23 @@ with gr.Blocks() as demo:
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()
 
6
  from gym_workout_classification import workout_classification
7
  from augmented_waste_classifier import waste_classification
8
  from age_classification import age_classification
9
+ from mnist_digits import classify_digit
10
 
11
  # Main classification function that calls the appropriate model based on selection.
12
  def classify(image, model_name):
 
24
  return waste_classification(image)
25
  elif model_name == "age":
26
  return age_classification(image)
27
+ elif model_name == "mnist":
28
+ return classify_digit(image)
29
  else:
30
  return {"Error": "No model selected"}
31
 
32
  # Function to update the selected model and button styles.
33
  def select_model(model_name):
34
+ model_variants = {
35
+ "gender": "secondary", "emotion": "secondary", "dog breed": "secondary", "deepfake": "secondary",
36
+ "gym workout": "secondary", "waste": "secondary", "age": "secondary", "mnist": "secondary"
37
+ }
38
+ model_variants[model_name] = "primary"
39
+ return (model_name, *(gr.update(variant=model_variants[key]) for key in model_variants))
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  with gr.Blocks() as demo:
 
42
  with gr.Sidebar():
43
  gr.Markdown("# SigLIP2 224")
44
  with gr.Row():
 
45
  age_btn = gr.Button("Age Classification", variant="primary")
46
  gender_btn = gr.Button("Gender Classification", variant="secondary")
47
  emotion_btn = gr.Button("Emotion Classification", variant="secondary")
 
49
  deepfake_btn = gr.Button("Deepfake vs Real", variant="secondary")
50
  gym_workout_btn = gr.Button("Gym Workout Classification", variant="secondary")
51
  waste_btn = gr.Button("Waste Classification", variant="secondary")
52
+ mnist_btn = gr.Button("MNIST Digit Classification", variant="secondary")
53
+
54
  selected_model = gr.State("age")
 
55
  gr.Markdown("### Current Model:")
56
  model_display = gr.Textbox(value="age", interactive=False)
 
57
  selected_model.change(lambda m: m, selected_model, model_display)
58
 
59
+ buttons = [gender_btn, emotion_btn, dog_breed_btn, deepfake_btn, gym_workout_btn, waste_btn, age_btn, mnist_btn]
60
+ model_names = ["gender", "emotion", "dog breed", "deepfake", "gym workout", "waste", "age", "mnist"]
61
+
62
+ for btn, name in zip(buttons, model_names):
63
+ btn.click(fn=lambda n=name: select_model(n), inputs=[], outputs=[selected_model] + buttons)
64
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  with gr.Column():
66
  image_input = gr.Image(type="numpy", label="Upload Image")
67
  analyze_btn = gr.Button("Classify / Predict")
68
  output_label = gr.Label(label="Prediction Scores")
 
69
  analyze_btn.click(fn=classify, inputs=[image_input, selected_model], outputs=output_label)
70
 
71
  demo.launch()