JKrishnanandhaa commited on
Commit
5611a24
·
verified ·
1 Parent(s): b37d4a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -13
app.py CHANGED
@@ -211,14 +211,33 @@ class ForgeryDetector:
211
  # Create visualization
212
  overlay = self._create_overlay(original_image, results)
213
 
214
- # Create gauge charts
215
- gauge_dice = create_gauge_chart(MODEL_METRICS['segmentation']['dice'], 'Segmentation Dice')
216
- gauge_accuracy = create_gauge_chart(MODEL_METRICS['classification']['overall_accuracy'], 'Classification Accuracy')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
 
218
  # Create HTML response
219
  results_html = self._create_html_report(results)
220
 
221
- return overlay, gauge_dice, gauge_accuracy, results_html
222
 
223
  def _create_overlay(self, image, results):
224
  """Create overlay visualization"""
@@ -312,15 +331,15 @@ def detect_forgery(file):
312
  try:
313
  if file is None:
314
  empty_html = "<div style='padding:12px; border:1px solid #d9534f; border-radius:8px;'>❌ <b>No file uploaded.</b></div>"
315
- return None, None, None, empty_html
316
 
317
  # Get file path
318
  file_path = file if isinstance(file, str) else file
319
 
320
  # Detect forgeries
321
- overlay, gauge_dice, gauge_acc, results_html = detector.detect(file_path)
322
 
323
- return overlay, gauge_dice, gauge_acc, results_html
324
 
325
  except Exception as e:
326
  import traceback
@@ -331,7 +350,7 @@ def detect_forgery(file):
331
  ❌ <b>Error:</b> {str(e)}
332
  </div>
333
  """
334
- return None, None, None, error_html
335
 
336
 
337
  # Custom CSS - subtle styling
@@ -397,8 +416,9 @@ with gr.Blocks(css=custom_css) as demo:
397
  with gr.Row():
398
  with gr.Column(scale=1):
399
  gr.Markdown("### Model Performance")
400
- gauge_dice = gr.Plot(label="Segmentation Dice Score")
401
- gauge_accuracy = gr.Plot(label="Classification Accuracy")
 
402
 
403
  with gr.Column(scale=1):
404
  gr.Markdown("### Analysis Report")
@@ -420,13 +440,13 @@ with gr.Blocks(css=custom_css) as demo:
420
  analyze_btn.click(
421
  fn=detect_forgery,
422
  inputs=[input_file],
423
- outputs=[output_image, gauge_dice, gauge_accuracy, output_html]
424
  )
425
 
426
  clear_btn.click(
427
- fn=lambda: (None, None, None, None, "<i>No analysis yet. Upload a document and click Analyze.</i>"),
428
  inputs=None,
429
- outputs=[input_file, output_image, gauge_dice, gauge_accuracy, output_html]
430
  )
431
 
432
 
 
211
  # Create visualization
212
  overlay = self._create_overlay(original_image, results)
213
 
214
+ # Create HTML for model performance metrics
215
+ model_performance_html = f"""
216
+ <div style='padding:12px; border:1px solid #444; border-radius:10px; background:var(--background-fill-primary);'>
217
+ <p style='margin-top:0; margin-bottom:12px;'><b>Trained Model Performance:</b></p>
218
+
219
+ <b>Segmentation Dice:</b>
220
+ <div style='width:100%; background:#333; height:12px; border-radius:6px; margin-bottom:12px;'>
221
+ <div style='width:{MODEL_METRICS['segmentation']['dice']*100:.1f}%; background:#4169E1; height:12px; border-radius:6px;'></div>
222
+ </div>
223
+
224
+ <b>Classification Accuracy:</b>
225
+ <div style='width:100%; background:#333; height:12px; border-radius:6px; margin-bottom:6px;'>
226
+ <div style='width:{MODEL_METRICS['classification']['overall_accuracy']*100:.1f}%; background:#5cb85c; height:12px; border-radius:6px;'></div>
227
+ </div>
228
+
229
+ <small style='opacity:0.8;'>
230
+ Dice: {MODEL_METRICS['segmentation']['dice']*100:.1f}% |
231
+ IoU: {MODEL_METRICS['segmentation']['iou']*100:.1f}% |
232
+ Accuracy: {MODEL_METRICS['classification']['overall_accuracy']*100:.1f}%
233
+ </small>
234
+ </div>
235
+ """
236
 
237
  # Create HTML response
238
  results_html = self._create_html_report(results)
239
 
240
+ return overlay, model_performance_html, results_html
241
 
242
  def _create_overlay(self, image, results):
243
  """Create overlay visualization"""
 
331
  try:
332
  if file is None:
333
  empty_html = "<div style='padding:12px; border:1px solid #d9534f; border-radius:8px;'>❌ <b>No file uploaded.</b></div>"
334
+ return None, empty_html, empty_html
335
 
336
  # Get file path
337
  file_path = file if isinstance(file, str) else file
338
 
339
  # Detect forgeries
340
+ overlay, model_perf_html, results_html = detector.detect(file_path)
341
 
342
+ return overlay, model_perf_html, results_html
343
 
344
  except Exception as e:
345
  import traceback
 
350
  ❌ <b>Error:</b> {str(e)}
351
  </div>
352
  """
353
+ return None, error_html, error_html
354
 
355
 
356
  # Custom CSS - subtle styling
 
416
  with gr.Row():
417
  with gr.Column(scale=1):
418
  gr.Markdown("### Model Performance")
419
+ model_performance = gr.HTML(
420
+ value="<i>Model performance will be shown after analysis.</i>"
421
+ )
422
 
423
  with gr.Column(scale=1):
424
  gr.Markdown("### Analysis Report")
 
440
  analyze_btn.click(
441
  fn=detect_forgery,
442
  inputs=[input_file],
443
+ outputs=[output_image, model_performance, output_html]
444
  )
445
 
446
  clear_btn.click(
447
+ fn=lambda: (None, None, "<i>Model performance will be shown after analysis.</i>", "<i>No analysis yet. Upload a document and click Analyze.</i>"),
448
  inputs=None,
449
+ outputs=[input_file, output_image, model_performance, output_html]
450
  )
451
 
452