paranox commited on
Commit
1f1cfda
·
verified ·
1 Parent(s): a2df24f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -291,7 +291,8 @@ def advanced_inference(
291
 
292
  # Strategy 2: Multi-scale inference (ensemble mode)
293
  if use_ensemble:
294
- scales = [img_size - 64, img_size + 64] if img_size >= 704 else [img_size]
 
295
  for scale in scales:
296
  results_scaled = model.predict(
297
  img,
@@ -421,7 +422,8 @@ def draw_boxes(image, boxes, show_conf=True, box_thickness=3):
421
  label_pos = "bottom"
422
 
423
  # Background rectangle with rounded appearance
424
- bg_coords = [x1, label_y, x1 + text_w + padding * 2, label_y + text_h + padding * 2]
 
425
  d.rectangle(bg_coords, fill=color + (240,))
426
 
427
  # Add subtle border to label
@@ -728,10 +730,10 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
728
  <div style="margin: 15px 0;">
729
  <span class="hackathon-badge">PARANOX 2.0</span>
730
  </div>
731
- <p style="font-size: 1.3em; margin: 10px 0; opacity: 0.9;">
732
  24-Hour National Innovation Hackathon | 3-Month Journey: Build → Pitch → Prototype
733
  </p>
734
- <p style="font-size: 1em; margin: 5px 0; opacity: 0.7;">
735
  🚀 Where Students Transform Ideas Into Reality
736
  </p>
737
  </div>
@@ -740,7 +742,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
740
  gr.Markdown("""
741
  <div style="text-align: center; padding: 30px 20px; background: linear-gradient(135deg, #ff6b6b15 0%, #ee5a6f15 100%); border-radius: 15px; margin-bottom: 20px;">
742
  <h1 style="font-size: 2.5em; margin-bottom: 10px;">🛡️ AI Safety Object Detector</h1>
743
- <p style="font-size: 1.2em; color: #555; margin: 10px 0;">
744
  <span class="accuracy-badge">MAXIMUM ACCURACY MODE</span><br>
745
  <span style="margin-top: 10px; display: inline-block;">Advanced YOLOv8 with Enhanced NMS & False Positive Suppression</span>
746
  </p>
@@ -773,7 +775,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
773
  )
774
 
775
  with gr.Accordion("🔬 Advanced Accuracy Boosters", open=True):
776
- gr.Markdown("**Performance Enhancers** - Enable for maximum accuracy")
 
777
  with gr.Row():
778
  use_tta = gr.Checkbox(
779
  value=True,
@@ -827,7 +830,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
827
  file_types=["image"],
828
  height=120
829
  )
830
- gr.Markdown("*💡 Tip: Upload multiple images to process them all at once and download as ZIP*")
 
831
 
832
  # ===== RIGHT PANEL: RESULTS & OUTPUT =====
833
  with gr.Column(scale=3):
@@ -847,7 +851,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
847
 
848
  with gr.Accordion("📊 Detailed Detection Table", open=True):
849
  out_table = gr.Dataframe(
850
- headers=["Class", "Confidence", "Top-Left (x,y)", "Bottom-Right (x,y)", "Area (px²)"],
 
851
  label="All Detections Sorted by Confidence",
852
  row_count=10,
853
  wrap=True
@@ -939,7 +944,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
939
 
940
  <div style="margin: 20px 0;">
941
  <h3 style="color: #ffd93d;">🎯 What is PARANOX 2.0?</h3>
942
- <p style="font-size: 1.1em; line-height: 1.6;">
943
  A <strong>24-hour national-level innovation hackathon</strong> where students transform their ideas into
944
  working prototypes. This isn't just a competition—it's a <strong>3-month journey</strong> of building,
945
  learning, and growing alongside India's brightest minds.
@@ -951,15 +956,15 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
951
  <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px; margin-top: 15px;">
952
  <div style="background: rgba(255, 107, 107, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #ff6b6b;">
953
  <h4 style="margin: 0 0 10px 0; color: #ff6b6b;">📝 Month 1: Build</h4>
954
- <p style="margin: 0;">Ideate, design, and develop your innovative solution with mentor guidance</p>
955
  </div>
956
  <div style="background: rgba(255, 211, 61, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #ffd93d;">
957
  <h4 style="margin: 0 0 10px 0; color: #ffd93d;">🎤 Month 2: Pitch</h4>
958
- <p style="margin: 0;">Present your prototype to industry experts and refine based on feedback</p>
959
  </div>
960
  <div style="background: rgba(16, 185, 129, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #10b981;">
961
  <h4 style="margin: 0 0 10px 0; color: #10b981;">🏗️ Month 3: Prototype</h4>
962
- <p style="margin: 0;">Polish your working prototype and compete in the 24-hour grand finale</p>
963
  </div>
964
  </div>
965
  </div>
@@ -978,7 +983,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
978
 
979
  <div style="margin: 20px 0;">
980
  <h3 style="color: #ffd93d;">🎯 This Project</h3>
981
- <p style="font-size: 1.1em; line-height: 1.6;">
982
  This <strong>AI Safety Object Detector</strong> was built as part of PARANOX 2.0, demonstrating
983
  how AI can solve real-world safety challenges. Using advanced YOLOv8 detection with enhanced
984
  accuracy techniques, it identifies safety equipment in images with industry-grade precision.
@@ -987,7 +992,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
987
 
988
  <div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 2px solid rgba(255, 255, 255, 0.2);">
989
  <h3 style="color: #ff6b6b; font-size: 1.8em; margin-bottom: 10px;">⚡ TechXNinjas</h3>
990
- <p style="font-size: 1.2em; opacity: 0.9;">Empowering Student Innovation | Building Tomorrow's Solutions Today</p>
991
  <div style="margin-top: 15px;">
992
  <span style="background: #ff6b6b; padding: 10px 25px; border-radius: 25px; margin: 0 10px; display: inline-block;">
993
  #PARANOX2024
@@ -1051,7 +1056,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
1051
  """)
1052
 
1053
  # ===== EVENT BINDINGS =====
1054
-
1055
  # Single image detection
1056
  detect_btn.click(
1057
  fn=predict_single,
@@ -1107,14 +1112,14 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0
1107
  gr.HTML("""
1108
  <div style="text-align: center; padding: 30px 20px; margin-top: 40px; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); border-radius: 15px; color: white;">
1109
  <h3 style="color: #ff6b6b; margin-bottom: 15px;">🚀 Built with Innovation & Passion</h3>
1110
- <p style="font-size: 1.1em; margin: 10px 0; color: white;">
1111
  Powered by <strong>TechXNinjas</strong> | PARANOX 2.0 Hackathon Project
1112
  </p>
1113
- <p style="opacity: 0.8; margin: 10px 0; color: white;">
1114
  24-Hour National Hackathon • 3-Month Innovation Journey • Student-Led Excellence
1115
  </p>
1116
  <div style="margin-top: 20px; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.2);">
1117
- <p style="opacity: 0.7; font-size: 0.9em; color: white;">
1118
  ⚠️ AI-Powered Tool • Always verify critical detections manually<br>
1119
  Made with ❤️ for safety and security applications
1120
  </p>
@@ -1136,7 +1141,7 @@ if __name__ == "__main__":
1136
  print(f"🖥️ Device: {device.upper()}")
1137
  print(f"⚡ Precision: {'FP16' if device == 'cuda' else 'FP32'}")
1138
  print("="*60 + "\n")
1139
-
1140
  demo.launch(
1141
  server_name="0.0.0.0",
1142
  server_port=7860,
@@ -1145,7 +1150,7 @@ if __name__ == "__main__":
1145
  show_api=False,
1146
  favicon_path=None
1147
  )
1148
-
1149
  print("\n✅ Application started successfully!")
1150
  print("🌐 Open your browser and navigate to the URL shown above")
1151
- print("⚠️ Press Ctrl+C to stop the server\n")
 
291
 
292
  # Strategy 2: Multi-scale inference (ensemble mode)
293
  if use_ensemble:
294
+ scales = [img_size - 64, img_size +
295
+ 64] if img_size >= 704 else [img_size]
296
  for scale in scales:
297
  results_scaled = model.predict(
298
  img,
 
422
  label_pos = "bottom"
423
 
424
  # Background rectangle with rounded appearance
425
+ bg_coords = [x1, label_y, x1 + text_w +
426
+ padding * 2, label_y + text_h + padding * 2]
427
  d.rectangle(bg_coords, fill=color + (240,))
428
 
429
  # Add subtle border to label
 
730
  <div style="margin: 15px 0;">
731
  <span class="hackathon-badge">PARANOX 2.0</span>
732
  </div>
733
+ <b style="font-size: 1.3em; margin: 10px 0; opacity: 0.9;">
734
  24-Hour National Innovation Hackathon | 3-Month Journey: Build → Pitch → Prototype
735
  </p>
736
+ <b style="font-size: 1em; margin: 5px 0; opacity: 0.7;">
737
  🚀 Where Students Transform Ideas Into Reality
738
  </p>
739
  </div>
 
742
  gr.Markdown("""
743
  <div style="text-align: center; padding: 30px 20px; background: linear-gradient(135deg, #ff6b6b15 0%, #ee5a6f15 100%); border-radius: 15px; margin-bottom: 20px;">
744
  <h1 style="font-size: 2.5em; margin-bottom: 10px;">🛡️ AI Safety Object Detector</h1>
745
+ <b style="font-size: 1.2em; color: #555; margin: 10px 0;">
746
  <span class="accuracy-badge">MAXIMUM ACCURACY MODE</span><br>
747
  <span style="margin-top: 10px; display: inline-block;">Advanced YOLOv8 with Enhanced NMS & False Positive Suppression</span>
748
  </p>
 
775
  )
776
 
777
  with gr.Accordion("🔬 Advanced Accuracy Boosters", open=True):
778
+ gr.Markdown(
779
+ "**Performance Enhancers** - Enable for maximum accuracy")
780
  with gr.Row():
781
  use_tta = gr.Checkbox(
782
  value=True,
 
830
  file_types=["image"],
831
  height=120
832
  )
833
+ gr.Markdown(
834
+ "*💡 Tip: Upload multiple images to process them all at once and download as ZIP*")
835
 
836
  # ===== RIGHT PANEL: RESULTS & OUTPUT =====
837
  with gr.Column(scale=3):
 
851
 
852
  with gr.Accordion("📊 Detailed Detection Table", open=True):
853
  out_table = gr.Dataframe(
854
+ headers=["Class", "Confidence",
855
+ "Top-Left (x,y)", "Bottom-Right (x,y)", "Area (px²)"],
856
  label="All Detections Sorted by Confidence",
857
  row_count=10,
858
  wrap=True
 
944
 
945
  <div style="margin: 20px 0;">
946
  <h3 style="color: #ffd93d;">🎯 What is PARANOX 2.0?</h3>
947
+ <b style="font-size: 1.1em; line-height: 1.6;">
948
  A <strong>24-hour national-level innovation hackathon</strong> where students transform their ideas into
949
  working prototypes. This isn't just a competition—it's a <strong>3-month journey</strong> of building,
950
  learning, and growing alongside India's brightest minds.
 
956
  <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px; margin-top: 15px;">
957
  <div style="background: rgba(255, 107, 107, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #ff6b6b;">
958
  <h4 style="margin: 0 0 10px 0; color: #ff6b6b;">📝 Month 1: Build</h4>
959
+ <b style="margin: 0;">Ideate, design, and develop your innovative solution with mentor guidance</p>
960
  </div>
961
  <div style="background: rgba(255, 211, 61, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #ffd93d;">
962
  <h4 style="margin: 0 0 10px 0; color: #ffd93d;">🎤 Month 2: Pitch</h4>
963
+ <b style="margin: 0;">Present your prototype to industry experts and refine based on feedback</p>
964
  </div>
965
  <div style="background: rgba(16, 185, 129, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #10b981;">
966
  <h4 style="margin: 0 0 10px 0; color: #10b981;">🏗️ Month 3: Prototype</h4>
967
+ <b style="margin: 0;">Polish your working prototype and compete in the 24-hour grand finale</p>
968
  </div>
969
  </div>
970
  </div>
 
983
 
984
  <div style="margin: 20px 0;">
985
  <h3 style="color: #ffd93d;">🎯 This Project</h3>
986
+ <b style="font-size: 1.1em; line-height: 1.6;">
987
  This <strong>AI Safety Object Detector</strong> was built as part of PARANOX 2.0, demonstrating
988
  how AI can solve real-world safety challenges. Using advanced YOLOv8 detection with enhanced
989
  accuracy techniques, it identifies safety equipment in images with industry-grade precision.
 
992
 
993
  <div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 2px solid rgba(255, 255, 255, 0.2);">
994
  <h3 style="color: #ff6b6b; font-size: 1.8em; margin-bottom: 10px;">⚡ TechXNinjas</h3>
995
+ <b style="font-size: 1.2em; opacity: 0.9;">Empowering Student Innovation | Building Tomorrow's Solutions Today</p>
996
  <div style="margin-top: 15px;">
997
  <span style="background: #ff6b6b; padding: 10px 25px; border-radius: 25px; margin: 0 10px; display: inline-block;">
998
  #PARANOX2024
 
1056
  """)
1057
 
1058
  # ===== EVENT BINDINGS =====
1059
+
1060
  # Single image detection
1061
  detect_btn.click(
1062
  fn=predict_single,
 
1112
  gr.HTML("""
1113
  <div style="text-align: center; padding: 30px 20px; margin-top: 40px; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); border-radius: 15px; color: white;">
1114
  <h3 style="color: #ff6b6b; margin-bottom: 15px;">🚀 Built with Innovation & Passion</h3>
1115
+ <b style="font-size: 1.1em; margin: 10px 0; color: white;">
1116
  Powered by <strong>TechXNinjas</strong> | PARANOX 2.0 Hackathon Project
1117
  </p>
1118
+ <b style="opacity: 0.8; margin: 10px 0; color: white;">
1119
  24-Hour National Hackathon • 3-Month Innovation Journey • Student-Led Excellence
1120
  </p>
1121
  <div style="margin-top: 20px; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.2);">
1122
+ <b style="opacity: 0.7; font-size: 0.9em; color: white;">
1123
  ⚠️ AI-Powered Tool • Always verify critical detections manually<br>
1124
  Made with ❤️ for safety and security applications
1125
  </p>
 
1141
  print(f"🖥️ Device: {device.upper()}")
1142
  print(f"⚡ Precision: {'FP16' if device == 'cuda' else 'FP32'}")
1143
  print("="*60 + "\n")
1144
+
1145
  demo.launch(
1146
  server_name="0.0.0.0",
1147
  server_port=7860,
 
1150
  show_api=False,
1151
  favicon_path=None
1152
  )
1153
+
1154
  print("\n✅ Application started successfully!")
1155
  print("🌐 Open your browser and navigate to the URL shown above")
1156
+ print("⚠️ Press Ctrl+C to stop the server\n")