haxerwddle commited on
Commit
14c97c3
·
1 Parent(s): 2ec8760

Model prompt change

Browse files
Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -83,11 +83,22 @@ def explain_recycling(class_label):
83
 
84
 
85
  # ------------------ PIPELINE ------------------
86
- def full_pipeline(image):
 
 
 
 
87
  predictions = classify_image(image)
88
  top_label = max(predictions, key=predictions.get) # top-1
 
 
 
 
 
 
 
89
  explanation = explain_recycling(top_label)
90
- return predictions, explanation
91
 
92
 
93
  # ------------------ GRADIO UI ------------------
@@ -181,6 +192,13 @@ with gr.Blocks() as demo:
181
  num_top_classes=3,
182
  label="🔍 Classifier Prediction (Top 3)"
183
  )
 
 
 
 
 
 
 
184
 
185
  explain_output = gr.Textbox(
186
  label="🧩 Detailed Recycling & Disposal Advice",
@@ -189,12 +207,12 @@ with gr.Blocks() as demo:
189
  )
190
 
191
  # BUTTON
192
- analyze_btn = gr.Button("Analyze Waste", variant="primary")
193
 
194
- analyze_btn.click(
195
- full_pipeline,
196
- inputs=img_input,
197
- outputs=[cls_output, explain_output]
198
  )
199
 
200
 
 
83
 
84
 
85
  # ------------------ PIPELINE ------------------
86
+ top_label = None
87
+
88
+ def classify_pipeline(image):
89
+ global top_label
90
+
91
  predictions = classify_image(image)
92
  top_label = max(predictions, key=predictions.get) # top-1
93
+ return predictions
94
+
95
+ def analyze_pipeline():
96
+ global top_label
97
+
98
+ if top_label is None:
99
+ return "Please classify an image first."
100
  explanation = explain_recycling(top_label)
101
+ return explanation
102
 
103
 
104
  # ------------------ GRADIO UI ------------------
 
192
  num_top_classes=3,
193
  label="🔍 Classifier Prediction (Top 3)"
194
  )
195
+ analyze_btn = gr.Button("Analyze Waste", variant="primary")
196
+
197
+ analyze_btn.click(
198
+ classify_pipeline,
199
+ inputs=img_input,
200
+ outputs=cls_output
201
+ )
202
 
203
  explain_output = gr.Textbox(
204
  label="🧩 Detailed Recycling & Disposal Advice",
 
207
  )
208
 
209
  # BUTTON
210
+ analyze_result_btn = gr.Button("Analyze Waste", variant="primary")
211
 
212
+ analyze_result_btn.click(
213
+ analyze_pipeline,
214
+ inputs=None,
215
+ outputs=explain_output
216
  )
217
 
218