Sarvamangalak commited on
Commit
4e4737b
·
verified ·
1 Parent(s): 8d3cf36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -33
app.py CHANGED
@@ -189,33 +189,6 @@ def get_dashboard():
189
  plt.tight_layout()
190
  return fig
191
 
192
- # ---------------- FEEDBACK ----------------
193
-
194
- def submit_feedback(result_text, feedback_choice):
195
- if not result_text:
196
- return "No result available."
197
-
198
- cursor.execute(
199
- "INSERT INTO feedback VALUES (?, ?)",
200
- (result_text, feedback_choice)
201
- )
202
- conn.commit()
203
- return "Feedback recorded!"
204
-
205
- def show_accuracy():
206
- df = pd.read_sql("SELECT * FROM feedback", conn)
207
-
208
- if df.empty:
209
- return "No feedback yet."
210
-
211
- correct = len(df[df["feedback"] == "Correct"])
212
- total = len(df)
213
-
214
- accuracy = (correct / total) * 100
215
- return f"Accuracy (User Feedback Based): {accuracy:.2f}%"
216
-
217
- # ---------------- CALLBACK ----------------
218
-
219
  def detect_image(img, threshold):
220
  if img is None:
221
  return None, "No image provided"
@@ -235,11 +208,12 @@ with gr.Blocks() as demo:
235
 
236
  result_box = gr.Textbox(label="Detection Result", lines=4)
237
 
238
- detect_btn = gr.Button("Detect")
239
  detect_btn.click(
240
- detect_image,
241
- inputs=[img_input, slider],
242
- outputs=[img_output, result_box]
 
243
  )
244
 
245
  gr.Markdown("### Feedback")
@@ -262,7 +236,31 @@ with gr.Blocks() as demo:
262
  gr.Markdown("### 📊 Dashboard")
263
  dashboard_plot = gr.Plot()
264
 
265
- refresh_btn = gr.Button("Refresh Dashboard")
266
- refresh_btn.click(get_dashboard, outputs=dashboard_plot)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
 
268
  demo.launch()
 
189
  plt.tight_layout()
190
  return fig
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  def detect_image(img, threshold):
193
  if img is None:
194
  return None, "No image provided"
 
208
 
209
  result_box = gr.Textbox(label="Detection Result", lines=4)
210
 
211
+ dashboard_plot = gr.Plot()
212
  detect_btn.click(
213
+ detect_image,
214
+ inputs=[img_input, slider],
215
+ outputs=[img_output, result_box, dashboard_plot]
216
+ )
217
  )
218
 
219
  gr.Markdown("### Feedback")
 
236
  gr.Markdown("### 📊 Dashboard")
237
  dashboard_plot = gr.Plot()
238
 
239
+ # ---------------- FEEDBACK ----------------
240
+
241
+ def submit_feedback(result_text, feedback_choice):
242
+ if not result_text:
243
+ return "No result available."
244
+
245
+ cursor.execute(
246
+ "INSERT INTO feedback VALUES (?, ?)",
247
+ (result_text, feedback_choice)
248
+ )
249
+ conn.commit()
250
+ return "Feedback recorded!"
251
+
252
+ def show_accuracy():
253
+ df = pd.read_sql("SELECT * FROM feedback", conn)
254
+
255
+ if df.empty:
256
+ return "No feedback yet."
257
+
258
+ correct = len(df[df["feedback"] == "Correct"])
259
+ total = len(df)
260
+
261
+ accuracy = (correct / total) * 100
262
+ return f"Accuracy (User Feedback Based): {accuracy:.2f}%"
263
+
264
+ # ---------------- CALLBACK ----------------
265
 
266
  demo.launch()