JohnJoelMota commited on
Commit
52ee1a9
ยท
verified ยท
1 Parent(s): bb11deb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -26
app.py CHANGED
@@ -388,11 +388,14 @@ def analyze_performance(image, category, user_opinion, frcnn_threshold=0.5, detr
388
 
389
  # Convert to HTML with styling
390
  html_analysis = f"""
391
- <div class="{'celebrate' if user_opinion in max_models else ''}">
392
- <h3 style='color: {"#4CAF50" if user_opinion in max_models else "#f44336"};'>
393
- {"๐Ÿ† Victory Achieved!" if user_opinion in max_models else "๐Ÿ’ช Keep Trying!"}
394
  </h3>
395
- <pre style='background: #fff; padding: 20px; border-radius: 10px;'>{analysis}</pre>
 
 
 
396
  </div>
397
  """
398
  return "Analysis complete!", frcnn_result, detr_result, maskrcnn_result, mask2former_result, html_analysis
@@ -404,7 +407,7 @@ with gr.Blocks(title="AI Vision Showdown", theme=gr.themes.Default(primary_hue="
404
  ### ๐Ÿค– Battle of the algorithms! Upload an image and predict which AI will dominate!
405
  """)
406
 
407
- # Custom CSS for animations
408
  gr.HTML("""
409
  <style>
410
  @keyframes celebrate {
@@ -415,15 +418,36 @@ with gr.Blocks(title="AI Vision Showdown", theme=gr.themes.Default(primary_hue="
415
  100% { transform: rotate(0deg); }
416
  }
417
  .celebrate { animation: celebrate 0.5s ease-in-out; }
418
- .win-border { border: 3px solid #4CAF50 !important; border-radius: 10px; }
419
- .battle-card { border-radius: 15px; padding: 20px; margin: 10px 0; background: #f5f5f5; }
420
- .tab-header { font-weight: bold !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  </style>
422
  """)
423
 
424
  # State variables
425
  image_state = gr.State(None)
426
  category_state = gr.State(None)
 
427
 
428
  # Top Section: Inputs
429
  with gr.Row(variant="battle-card"):
@@ -434,16 +458,16 @@ with gr.Blocks(title="AI Vision Showdown", theme=gr.themes.Default(primary_hue="
434
 
435
  with gr.Column(scale=1, min_width=300):
436
  with gr.Group(visible=False) as prediction_selection:
437
- gr.Markdown("## ๐Ÿค” Prediction Panel")
438
  category_choice = gr.Radio(
439
  choices=["Object Detection", "Object Segmentation"],
440
- label="โš”๏ธ Battle Type Selection",
441
  value=None,
442
  elem_classes="battle-card"
443
  )
444
  user_opinion = gr.Radio(
445
  choices=[],
446
- label="๐Ÿ† Which Warrior Will Win?",
447
  value=None,
448
  visible=False,
449
  elem_classes="battle-card"
@@ -523,25 +547,36 @@ with gr.Blocks(title="AI Vision Showdown", theme=gr.themes.Default(primary_hue="
523
  def run_detection(image, category, user_opinion, frcnn_threshold, detr_threshold, maskrcnn_threshold, mask2former_threshold):
524
  if not category or not user_opinion:
525
  return "Please select a category and prediction.", None, None, None, None, "No analysis available.", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
526
- result = analyze_performance(image, category, user_opinion, frcnn_threshold, detr_threshold, maskrcnn_threshold, mask2former_threshold)
527
- message, frcnn_result_img, detr_result_img, maskrcnn_result_img, mask2former_result_img, html_analysis = result
528
- return [
529
- message,
530
- gr.update(value=frcnn_result_img, visible=category == "Object Detection"),
531
- gr.update(value=detr_result_img, visible=category == "Object Detection"),
532
- gr.update(value=maskrcnn_result_img, visible=category == "Object Segmentation"),
533
- gr.update(value=mask2former_result_img, visible=category == "Object Segmentation"),
534
- html_analysis,
535
- gr.update(visible=True),
536
- gr.update(visible=True),
537
- gr.update(visible=category == "Object Detection"),
538
- gr.update(visible=category == "Object Segmentation")
539
- ]
 
 
 
 
 
 
 
 
 
 
540
 
541
  detect_button.click(
542
  fn=run_detection,
543
  inputs=[image_state, category_state, user_opinion, frcnn_threshold, detr_threshold, maskrcnn_threshold, mask2former_threshold],
544
- outputs=[gr.Textbox(visible=False), frcnn_result, detr_result, maskrcnn_result, mask2former_result, analysis_output, outputs_panel, results_panel, detection_tab, segmentation_tab]
 
545
  )
546
 
547
  # Restart button click event
 
388
 
389
  # Convert to HTML with styling
390
  html_analysis = f"""
391
+ <div class="{'celebrate' if user_opinion in max_models else ''}" style="margin: 15px 0;">
392
+ <h3 style='color: {"#4CAF50" if user_opinion in max_models else "#f44336"}; margin-bottom: 15px;'>
393
+ {"๐Ÿ† " + max_models[0] + " Dominates!" if len(max_models) == 1 else "โš”๏ธ Tie Battle!"}
394
  </h3>
395
+ <div style="background: var(--background-fill-primary); padding: 20px; border-radius: 10px;
396
+ white-space: pre-wrap; overflow-wrap: break-word; color: var(--text-color);">
397
+ {analysis}
398
+ </div>
399
  </div>
400
  """
401
  return "Analysis complete!", frcnn_result, detr_result, maskrcnn_result, mask2former_result, html_analysis
 
407
  ### ๐Ÿค– Battle of the algorithms! Upload an image and predict which AI will dominate!
408
  """)
409
 
410
+ # Enhanced CSS
411
  gr.HTML("""
412
  <style>
413
  @keyframes celebrate {
 
418
  100% { transform: rotate(0deg); }
419
  }
420
  .celebrate { animation: celebrate 0.5s ease-in-out; }
421
+ .battle-card {
422
+ border-radius: 15px;
423
+ padding: 20px;
424
+ margin: 10px 0;
425
+ background: var(--background-fill-primary);
426
+ border: 1px solid var(--border-color-primary);
427
+ }
428
+ .analysis-box {
429
+ background: var(--background-fill-secondary) !important;
430
+ color: var(--text-color) !important;
431
+ padding: 20px;
432
+ border-radius: 10px;
433
+ white-space: pre-wrap;
434
+ overflow-wrap: break-word;
435
+ }
436
+ .loading-status {
437
+ padding: 15px;
438
+ background: var(--background-fill-secondary);
439
+ border-radius: 8px;
440
+ margin: 10px 0;
441
+ text-align: center;
442
+ font-weight: bold;
443
+ }
444
  </style>
445
  """)
446
 
447
  # State variables
448
  image_state = gr.State(None)
449
  category_state = gr.State(None)
450
+ loading_status = gr.HTML(visible=False)
451
 
452
  # Top Section: Inputs
453
  with gr.Row(variant="battle-card"):
 
458
 
459
  with gr.Column(scale=1, min_width=300):
460
  with gr.Group(visible=False) as prediction_selection:
461
+ gr.Markdown("## ๐Ÿ”ฎ Prediction Arena")
462
  category_choice = gr.Radio(
463
  choices=["Object Detection", "Object Segmentation"],
464
+ label="โš”๏ธ Select Battle Ground",
465
  value=None,
466
  elem_classes="battle-card"
467
  )
468
  user_opinion = gr.Radio(
469
  choices=[],
470
+ label="๐Ÿน Predict the Victor",
471
  value=None,
472
  visible=False,
473
  elem_classes="battle-card"
 
547
  def run_detection(image, category, user_opinion, frcnn_threshold, detr_threshold, maskrcnn_threshold, mask2former_threshold):
548
  if not category or not user_opinion:
549
  return "Please select a category and prediction.", None, None, None, None, "No analysis available.", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
550
+
551
+ def analyze_with_progress(progress=gr.Progress()):
552
+ progress(0.1, desc="โš™๏ธ Models are gearing up...")
553
+ result = analyze_performance(image, category, user_opinion, frcnn_threshold, detr_threshold, maskrcnn_threshold, mask2former_threshold)
554
+ progress(1.0, desc="โœ… Battle complete!")
555
+ return result
556
+
557
+ try:
558
+ message, frcnn_result_img, detr_result_img, maskrcnn_result_img, mask2former_result_img, html_analysis = analyze_with_progress()
559
+ return [
560
+ message,
561
+ gr.update(value=frcnn_result_img, visible=category == "Object Detection"),
562
+ gr.update(value=detr_result_img, visible=category == "Object Detection"),
563
+ gr.update(value=maskrcnn_result_img, visible=category == "Object Segmentation"),
564
+ gr.update(value=mask2former_result_img, visible=category == "Object Segmentation"),
565
+ html_analysis,
566
+ gr.update(visible=True),
567
+ gr.update(visible=True),
568
+ gr.update(visible=category == "Object Detection"),
569
+ gr.update(visible=category == "Object Segmentation"),
570
+ gr.update(visible=False)
571
+ ]
572
+ except Exception as e:
573
+ return [f"Error: {str(e)}"] + [gr.update()]*9 + [gr.update(visible=False)]
574
 
575
  detect_button.click(
576
  fn=run_detection,
577
  inputs=[image_state, category_state, user_opinion, frcnn_threshold, detr_threshold, maskrcnn_threshold, mask2former_threshold],
578
+ outputs=[gr.Textbox(visible=False), frcnn_result, detr_result, maskrcnn_result, mask2former_result,
579
+ analysis_output, outputs_panel, results_panel, detection_tab, segmentation_tab, loading_status]
580
  )
581
 
582
  # Restart button click event