Update app.py
Browse files
app.py
CHANGED
|
@@ -291,8 +291,7 @@ def advanced_inference(
|
|
| 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,8 +421,7 @@ def draw_boxes(image, boxes, show_conf=True, box_thickness=3):
|
|
| 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
|
|
@@ -657,7 +655,7 @@ def predict_batch(files, conf, iou, use_tta, img_size, use_ensemble, enhance_img
|
|
| 657 |
|
| 658 |
|
| 659 |
# ==========================================================
|
| 660 |
-
# GRADIO UI (PREMIUM DESIGN)
|
| 661 |
# ==========================================================
|
| 662 |
css = """
|
| 663 |
.gradio-container {
|
|
@@ -666,7 +664,7 @@ css = """
|
|
| 666 |
margin: auto;
|
| 667 |
}
|
| 668 |
.primary-btn {
|
| 669 |
-
background: linear-gradient(135deg, #
|
| 670 |
border: none !important;
|
| 671 |
color: white !important;
|
| 672 |
font-weight: 600 !important;
|
|
@@ -675,7 +673,7 @@ css = """
|
|
| 675 |
}
|
| 676 |
.primary-btn:hover {
|
| 677 |
transform: translateY(-2px) !important;
|
| 678 |
-
box-shadow: 0 12px 24px rgba(
|
| 679 |
}
|
| 680 |
.stats-box {
|
| 681 |
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
|
@@ -694,24 +692,59 @@ css = """
|
|
| 694 |
font-size: 14px;
|
| 695 |
box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
|
| 696 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
.header-gradient {
|
| 698 |
-
background: linear-gradient(135deg, #
|
| 699 |
-webkit-background-clip: text;
|
| 700 |
-webkit-text-fill-color: transparent;
|
| 701 |
background-clip: text;
|
| 702 |
}
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
|
| 707 |
gr.Markdown("""
|
| 708 |
-
<div style
|
| 709 |
-
<h1 style
|
| 710 |
-
<p style
|
| 711 |
-
<span class
|
| 712 |
-
<span style
|
| 713 |
-
</p
|
| 714 |
-
</div
|
| 715 |
""")
|
| 716 |
|
| 717 |
with gr.Row():
|
|
@@ -740,8 +773,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
|
|
| 740 |
)
|
| 741 |
|
| 742 |
with gr.Accordion("π¬ Advanced Accuracy Boosters", open=True):
|
| 743 |
-
gr.Markdown(
|
| 744 |
-
"**Performance Enhancers** - Enable for maximum accuracy")
|
| 745 |
with gr.Row():
|
| 746 |
use_tta = gr.Checkbox(
|
| 747 |
value=True,
|
|
@@ -795,8 +827,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
|
|
| 795 |
file_types=["image"],
|
| 796 |
height=120
|
| 797 |
)
|
| 798 |
-
gr.Markdown(
|
| 799 |
-
"*π‘ Tip: Upload multiple images to process them all at once and download as ZIP*")
|
| 800 |
|
| 801 |
# ===== RIGHT PANEL: RESULTS & OUTPUT =====
|
| 802 |
with gr.Column(scale=3):
|
|
@@ -816,8 +847,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
|
|
| 816 |
|
| 817 |
with gr.Accordion("π Detailed Detection Table", open=True):
|
| 818 |
out_table = gr.Dataframe(
|
| 819 |
-
headers=["Class", "Confidence",
|
| 820 |
-
"Top-Left (x,y)", "Bottom-Right (x,y)", "Area (pxΒ²)"],
|
| 821 |
label="All Detections Sorted by Confidence",
|
| 822 |
row_count=10,
|
| 823 |
wrap=True
|
|
@@ -836,164 +866,141 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
|
|
| 836 |
# ===== TIPS & CONFIGURATION GUIDE =====
|
| 837 |
with gr.Accordion("π‘ Configuration Guide - Get Best Results", open=False):
|
| 838 |
gr.Markdown("""
|
| 839 |
-
# π― Recommended Settings by Use Case
|
| 840 |
|
| 841 |
-
# π MAXIMUM ACCURACY (Best for Critical Applications)
|
| 842 |
Perfect for: Safety inspections, compliance checks, detailed analysis
|
| 843 |
|
| 844 |
| Parameter | Value | Why? |
|
| 845 |
-
|-----------
|
| 846 |
| Confidence | `0.35-0.45` | Filters out most false positives while keeping real objects |
|
| 847 |
| IoU | `0.45-0.55` | Good balance for overlapping objects |
|
| 848 |
-
| TTA | β
**
|
| 849 |
-
| Ensemble | β
**
|
| 850 |
-
| Enhancement | β
**
|
| 851 |
| Image Size | `800-1024px` | Better for small and distant objects |
|
| 852 |
|
| 853 |
-
**Expected Performance:
|
| 854 |
|
| 855 |
---
|
| 856 |
|
| 857 |
-
# β‘ BALANCED MODE (Speed + Accuracy)
|
| 858 |
Perfect for: General use, moderate batch processing
|
| 859 |
|
| 860 |
| Parameter | Value | Why? |
|
| 861 |
-
|-----------
|
| 862 |
| Confidence | `0.30-0.40` | Good detection rate with acceptable false positives |
|
| 863 |
| IoU | `0.45-0.50` | Standard NMS threshold |
|
| 864 |
-
| TTA | β
**
|
| 865 |
-
| Ensemble | β **
|
| 866 |
-
| Enhancement | β
**
|
| 867 |
| Image Size | `640px` | Fast and sufficient for most cases |
|
| 868 |
|
| 869 |
-
**Expected Performance:
|
| 870 |
|
| 871 |
---
|
| 872 |
|
| 873 |
-
# π SPEED MODE (Real-time/Batch)
|
| 874 |
Perfect for: Large batches, real-time monitoring, quick scans
|
| 875 |
|
| 876 |
| Parameter | Value | Why? |
|
| 877 |
-
|-----------
|
| 878 |
| Confidence | `0.40-0.55` | Higher threshold = fewer detections but faster |
|
| 879 |
| IoU | `0.50-0.60` | Standard NMS, less computation |
|
| 880 |
-
| TTA | β **
|
| 881 |
-
| Ensemble | β **
|
| 882 |
-
| Enhancement | β **
|
| 883 |
| Image Size | `640px` | Fastest inference size |
|
| 884 |
|
| 885 |
-
**Expected Performance:
|
| 886 |
|
| 887 |
---
|
| 888 |
|
| 889 |
-
# π Understanding Each Parameter
|
| 890 |
-
|
| 891 |
-
# Confidence Threshold (0.05 - 0.95)
|
| 892 |
-
- **What it does: ** Minimum probability score for a detection to be kept
|
| 893 |
-
- **Lower(0.15-0.25): ** More detections, more false positives
|
| 894 |
-
- **Higher(0.40-0.60): ** Fewer detections, fewer false positives
|
| 895 |
-
- **Sweet spot: ** 0.30-0.40 for most use cases
|
| 896 |
-
|
| 897 |
-
# IoU Threshold (0.10 - 0.95)
|
| 898 |
-
- **What it does: ** Controls how much boxes can overlap before one is removed(Non-Maximum Suppression)
|
| 899 |
-
- **Lower(0.30-0.40): ** More aggressive overlap removal, fewer boxes kept
|
| 900 |
-
- **Higher(0.50-0.70): ** Keeps more overlapping boxes(good for crowded scenes)
|
| 901 |
-
- **Sweet spot: ** 0.45-0.55 for most use cases
|
| 902 |
-
|
| 903 |
-
# Test-Time Augmentation (TTA)
|
| 904 |
-
- **What it does: ** Runs detection on multiple augmented versions of the image(flips, scales) and averages results
|
| 905 |
-
- **Pros: ** +3-7 % mAP improvement, more robust to image variations
|
| 906 |
-
- **Cons: ** 2-3x slower inference
|
| 907 |
-
- **Use when: ** Accuracy is critical, small/hard-to-detect objects
|
| 908 |
-
|
| 909 |
-
# Multi-Scale Ensemble
|
| 910 |
-
- **What it does: ** Runs detection at multiple image sizes and merges predictions
|
| 911 |
-
- **Pros: ** +2-5 % mAP, better for objects of varying sizes
|
| 912 |
-
- **Cons: ** 2-4x slower inference
|
| 913 |
-
- **Use when: ** Scene has both large and small objects, maximum accuracy needed
|
| 914 |
-
|
| 915 |
-
# Image Enhancement
|
| 916 |
-
- **What it does: ** Applies contrast, sharpness, and brightness adjustments before detection
|
| 917 |
-
- **Pros: ** Improves detection on low-quality/dark images, minimal speed cost
|
| 918 |
-
- **Cons: ** May hurt performance on already high-quality images
|
| 919 |
-
- **Use when: ** Images are low-quality, poorly lit, or low contrast
|
| 920 |
-
|
| 921 |
-
# Image Size
|
| 922 |
-
- **What it does: ** Resizes input image before detection
|
| 923 |
-
- **640px: ** Fast, good for large objects
|
| 924 |
-
- **800px: ** Balanced, handles medium-small objects well
|
| 925 |
-
- **1024px: ** Slower, best for small/distant objects
|
| 926 |
-
- **1280px: ** Slowest, maximum detail preservation
|
| 927 |
|
| 928 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 929 |
|
| 930 |
-
#
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
#
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 997 |
""")
|
| 998 |
|
| 999 |
# ===== MODEL INFORMATION =====
|
|
@@ -1041,79 +1048,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
|
|
| 1041 |
- Containment-based filtering (boxes inside other boxes)
|
| 1042 |
- High-overlap cross-class suppression
|
| 1043 |
- Confidence-based quality assessment
|
| 1044 |
-
|
| 1045 |
-
β
**Enhanced Visualization**
|
| 1046 |
-
- Adaptive box thickness based on confidence
|
| 1047 |
-
- Corner markers for better visibility
|
| 1048 |
-
- Color-coded class labels with shadows
|
| 1049 |
-
- Confidence quality indicators
|
| 1050 |
-
|
| 1051 |
-
## π Performance Characteristics
|
| 1052 |
-
|
| 1053 |
-
| Metric | Value |
|
| 1054 |
-
|--------|-------|
|
| 1055 |
-
| Base Inference Speed (640px) | ~30-50 FPS (GPU) / ~5-10 FPS (CPU) |
|
| 1056 |
-
| With TTA | ~10-15 FPS (GPU) / ~2-3 FPS (CPU) |
|
| 1057 |
-
| With TTA + Ensemble | ~3-5 FPS (GPU) / ~0.5-1 FPS (CPU) |
|
| 1058 |
-
| Maximum Image Size | 1280px |
|
| 1059 |
-
| Maximum Detections | 150 per image |
|
| 1060 |
-
| Supported Formats | JPG, PNG, BMP, TIFF |
|
| 1061 |
-
|
| 1062 |
-
## π§ Technical Implementation
|
| 1063 |
-
|
| 1064 |
-
**Framework:** Ultralytics YOLOv8 + PyTorch {torch.__version__}
|
| 1065 |
-
**UI Framework:** Gradio {gr.__version__}
|
| 1066 |
-
**Inference Optimizations:**
|
| 1067 |
-
- Half-precision (FP16) on CUDA
|
| 1068 |
-
- Agnostic NMS enabled
|
| 1069 |
-
- Batch processing with ZIP compression
|
| 1070 |
-
- Optimized image I/O with PIL
|
| 1071 |
-
|
| 1072 |
-
""")
|
| 1073 |
-
|
| 1074 |
-
# ===== ABOUT & CREDITS =====
|
| 1075 |
-
with gr.Accordion("βΉοΈ About & Credits", open=False):
|
| 1076 |
-
gr.Markdown("""
|
| 1077 |
-
## π Duality AI - Safety Object Detector
|
| 1078 |
-
|
| 1079 |
-
**Version:** 2.0 (Enhanced)
|
| 1080 |
-
**Last Updated:** November 2025
|
| 1081 |
-
|
| 1082 |
-
### π― Purpose
|
| 1083 |
-
This application provides state-of-the-art object detection for safety equipment identification.
|
| 1084 |
-
It combines multiple advanced techniques to maximize detection accuracy while minimizing false positives.
|
| 1085 |
-
|
| 1086 |
-
### ποΈ Built With
|
| 1087 |
-
- **YOLOv8** - Ultralytics' state-of-the-art object detection
|
| 1088 |
-
- **PyTorch** - Deep learning framework
|
| 1089 |
-
- **Gradio** - Interactive ML web interface
|
| 1090 |
-
- **PIL/Pillow** - Image processing
|
| 1091 |
-
- **NumPy** - Numerical computations
|
| 1092 |
-
|
| 1093 |
-
### π Citation
|
| 1094 |
-
If you use this tool in your research or work, please cite:
|
| 1095 |
-
```
|
| 1096 |
-
@software{duality_ai_detector_2025,
|
| 1097 |
-
title={Duality AI Safety Object Detector},
|
| 1098 |
-
author={Duality AI Team},
|
| 1099 |
-
year={2025},
|
| 1100 |
-
version={2.0}
|
| 1101 |
-
}
|
| 1102 |
-
```
|
| 1103 |
-
|
| 1104 |
-
### π€ Contributing
|
| 1105 |
-
We welcome contributions! This is an open system designed to be improved by the community.
|
| 1106 |
-
|
| 1107 |
-
### π License
|
| 1108 |
-
This software is provided as-is for safety and security applications.
|
| 1109 |
-
|
| 1110 |
-
### β οΈ Disclaimer
|
| 1111 |
-
This is an AI-powered tool and may not be 100% accurate. Always verify critical detections manually.
|
| 1112 |
-
Not intended to replace professional safety inspections.
|
| 1113 |
-
|
| 1114 |
-
---
|
| 1115 |
-
|
| 1116 |
-
**Made with β€οΈ for safety and security**
|
| 1117 |
""")
|
| 1118 |
|
| 1119 |
# ===== EVENT BINDINGS =====
|
|
@@ -1156,7 +1090,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
|
|
| 1156 |
gr.Markdown("""
|
| 1157 |
**Try these configurations for common scenarios:**
|
| 1158 |
|
| 1159 |
-
1. **Single clear object (like
|
| 1160 |
- Confidence: 0.40, IoU: 0.50, TTA: β
, Ensemble: β, Size: 640px
|
| 1161 |
|
| 1162 |
2. **Multiple small objects:**
|
|
@@ -1169,13 +1103,33 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
|
|
| 1169 |
- Confidence: 0.30, IoU: 0.50, TTA: β
, Enhancement: β
, Size: 800px
|
| 1170 |
""")
|
| 1171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1172 |
|
| 1173 |
# ==========================================================
|
| 1174 |
# LAUNCH APPLICATION
|
| 1175 |
# ==========================================================
|
| 1176 |
if __name__ == "__main__":
|
| 1177 |
print("\n" + "="*60)
|
| 1178 |
-
print("
|
|
|
|
| 1179 |
print("="*60)
|
| 1180 |
print(f"π¦ Model: {MODEL_PATH}")
|
| 1181 |
print(f"π·οΈ Classes: {len(CLASS_NAMES)}")
|
|
|
|
| 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 |
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
|
|
|
|
| 655 |
|
| 656 |
|
| 657 |
# ==========================================================
|
| 658 |
+
# GRADIO UI (PREMIUM DESIGN WITH TECHXNINJAS BRANDING)
|
| 659 |
# ==========================================================
|
| 660 |
css = """
|
| 661 |
.gradio-container {
|
|
|
|
| 664 |
margin: auto;
|
| 665 |
}
|
| 666 |
.primary-btn {
|
| 667 |
+
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%) !important;
|
| 668 |
border: none !important;
|
| 669 |
color: white !important;
|
| 670 |
font-weight: 600 !important;
|
|
|
|
| 673 |
}
|
| 674 |
.primary-btn:hover {
|
| 675 |
transform: translateY(-2px) !important;
|
| 676 |
+
box-shadow: 0 12px 24px rgba(255, 107, 107, 0.4) !important;
|
| 677 |
}
|
| 678 |
.stats-box {
|
| 679 |
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
|
|
|
| 692 |
font-size: 14px;
|
| 693 |
box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
|
| 694 |
}
|
| 695 |
+
.hackathon-badge {
|
| 696 |
+
display: inline-block;
|
| 697 |
+
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
|
| 698 |
+
color: white;
|
| 699 |
+
padding: 8px 20px;
|
| 700 |
+
border-radius: 25px;
|
| 701 |
+
font-weight: bold;
|
| 702 |
+
font-size: 16px;
|
| 703 |
+
margin: 10px 5px;
|
| 704 |
+
box-shadow: 0 4px 8px rgba(255, 107, 107, 0.3);
|
| 705 |
+
}
|
| 706 |
.header-gradient {
|
| 707 |
+
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
|
| 708 |
-webkit-background-clip: text;
|
| 709 |
-webkit-text-fill-color: transparent;
|
| 710 |
background-clip: text;
|
| 711 |
}
|
| 712 |
+
.paranox-banner {
|
| 713 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
|
| 714 |
+
color: white;
|
| 715 |
+
padding: 25px;
|
| 716 |
+
border-radius: 15px;
|
| 717 |
+
text-align: center;
|
| 718 |
+
margin-bottom: 20px;
|
| 719 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
|
| 720 |
+
}
|
| 721 |
+
"""
|
| 722 |
+
|
| 723 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0 - Safety Detector") as demo:
|
| 724 |
+
|
| 725 |
+
gr.HTML("""
|
| 726 |
+
<div class="paranox-banner">
|
| 727 |
+
<h1 style="font-size: 3em; margin: 0; font-weight: bold;">β‘ TechXNinjas</h1>
|
| 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>
|
| 738 |
+
""")
|
| 739 |
|
| 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>
|
| 747 |
+
</div>
|
| 748 |
""")
|
| 749 |
|
| 750 |
with gr.Row():
|
|
|
|
| 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 |
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 |
|
| 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
|
|
|
|
| 866 |
# ===== TIPS & CONFIGURATION GUIDE =====
|
| 867 |
with gr.Accordion("π‘ Configuration Guide - Get Best Results", open=False):
|
| 868 |
gr.Markdown("""
|
| 869 |
+
## π― Recommended Settings by Use Case
|
| 870 |
|
| 871 |
+
### π MAXIMUM ACCURACY (Best for Critical Applications)
|
| 872 |
Perfect for: Safety inspections, compliance checks, detailed analysis
|
| 873 |
|
| 874 |
| Parameter | Value | Why? |
|
| 875 |
+
|-----------|-------|------|
|
| 876 |
| Confidence | `0.35-0.45` | Filters out most false positives while keeping real objects |
|
| 877 |
| IoU | `0.45-0.55` | Good balance for overlapping objects |
|
| 878 |
+
| TTA | β
**Enabled** | +3-7% accuracy through augmentation |
|
| 879 |
+
| Ensemble | β
**Enabled** | +2-5% accuracy through multi-scale detection |
|
| 880 |
+
| Enhancement | β
**Enabled** | Improves detection on low-quality images |
|
| 881 |
| Image Size | `800-1024px` | Better for small and distant objects |
|
| 882 |
|
| 883 |
+
**Expected Performance:** Best accuracy, ~5-10 seconds per image
|
| 884 |
|
| 885 |
---
|
| 886 |
|
| 887 |
+
### β‘ BALANCED MODE (Speed + Accuracy)
|
| 888 |
Perfect for: General use, moderate batch processing
|
| 889 |
|
| 890 |
| Parameter | Value | Why? |
|
| 891 |
+
|-----------|-------|------|
|
| 892 |
| Confidence | `0.30-0.40` | Good detection rate with acceptable false positives |
|
| 893 |
| IoU | `0.45-0.50` | Standard NMS threshold |
|
| 894 |
+
| TTA | β
**Enabled** | Worth the small speed cost |
|
| 895 |
+
| Ensemble | β **Disabled** | Too slow for marginal gains |
|
| 896 |
+
| Enhancement | β
**Enabled** | Fast and helpful |
|
| 897 |
| Image Size | `640px` | Fast and sufficient for most cases |
|
| 898 |
|
| 899 |
+
**Expected Performance:** Good accuracy, ~2-3 seconds per image
|
| 900 |
|
| 901 |
---
|
| 902 |
|
| 903 |
+
### π SPEED MODE (Real-time/Batch)
|
| 904 |
Perfect for: Large batches, real-time monitoring, quick scans
|
| 905 |
|
| 906 |
| Parameter | Value | Why? |
|
| 907 |
+
|-----------|-------|------|
|
| 908 |
| Confidence | `0.40-0.55` | Higher threshold = fewer detections but faster |
|
| 909 |
| IoU | `0.50-0.60` | Standard NMS, less computation |
|
| 910 |
+
| TTA | β **Disabled** | Too slow for speed mode |
|
| 911 |
+
| Ensemble | β **Disabled** | Significantly slower |
|
| 912 |
+
| Enhancement | β **Disabled** | Save preprocessing time |
|
| 913 |
| Image Size | `640px` | Fastest inference size |
|
| 914 |
|
| 915 |
+
**Expected Performance:** Fast, ~0.5-1 second per image
|
| 916 |
|
| 917 |
---
|
| 918 |
|
| 919 |
+
## π Understanding Each Parameter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 920 |
|
| 921 |
+
### Confidence Threshold (0.05-0.95)
|
| 922 |
+
- **What it does:** Minimum probability score for a detection to be kept
|
| 923 |
+
- **Lower (0.15-0.25):** More detections, more false positives
|
| 924 |
+
- **Higher (0.40-0.60):** Fewer detections, fewer false positives
|
| 925 |
+
- **Sweet spot:** 0.30-0.40 for most use cases
|
| 926 |
|
| 927 |
+
### IoU Threshold (0.10-0.95)
|
| 928 |
+
- **What it does:** Controls how much boxes can overlap before one is removed (Non-Maximum Suppression)
|
| 929 |
+
- **Lower (0.30-0.40):** More aggressive overlap removal, fewer boxes kept
|
| 930 |
+
- **Higher (0.50-0.70):** Keeps more overlapping boxes (good for crowded scenes)
|
| 931 |
+
- **Sweet spot:** 0.45-0.55 for most use cases
|
| 932 |
+
""")
|
| 933 |
+
|
| 934 |
+
# ===== HACKATHON INFO =====
|
| 935 |
+
with gr.Accordion("π About PARANOX 2.0 - TechXNinjas", open=True):
|
| 936 |
+
gr.HTML("""
|
| 937 |
+
<div style="padding: 20px; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); border-radius: 15px; color: white;">
|
| 938 |
+
<h2 style="color: #ff6b6b; margin-top: 0;">β‘ PARANOX 2.0 - National Innovation Hackathon</h2>
|
| 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.
|
| 946 |
+
</p>
|
| 947 |
+
</div>
|
| 948 |
+
|
| 949 |
+
<div style="margin: 20px 0;">
|
| 950 |
+
<h3 style="color: #ffd93d;">π The Journey</h3>
|
| 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>
|
| 966 |
+
|
| 967 |
+
<div style="margin: 20px 0;">
|
| 968 |
+
<h3 style="color: #ffd93d;">β¨ Why PARANOX 2.0?</h3>
|
| 969 |
+
<ul style="font-size: 1.05em; line-height: 1.8;">
|
| 970 |
+
<li>π <strong>Learn by Doing:</strong> Real-world problem solving with cutting-edge technologies</li>
|
| 971 |
+
<li>π€ <strong>Network:</strong> Connect with 100+ students, mentors, and industry professionals</li>
|
| 972 |
+
<li>π <strong>Compete:</strong> Showcase your skills at a national level</li>
|
| 973 |
+
<li>π‘ <strong>Innovate:</strong> Turn your ideas into tangible products</li>
|
| 974 |
+
<li>π <strong>Win:</strong> Exciting prizes, internships, and recognition</li>
|
| 975 |
+
<li>π <strong>Grow:</strong> 3 months of continuous learning and improvement</li>
|
| 976 |
+
</ul>
|
| 977 |
+
</div>
|
| 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.
|
| 985 |
+
</p>
|
| 986 |
+
</div>
|
| 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
|
| 994 |
+
</span>
|
| 995 |
+
<span style="background: #ffd93d; color: #1a1a2e; padding: 10px 25px; border-radius: 25px; margin: 0 10px; display: inline-block;">
|
| 996 |
+
#TechXNinjas
|
| 997 |
+
</span>
|
| 998 |
+
<span style="background: #10b981; padding: 10px 25px; border-radius: 25px; margin: 0 10px; display: inline-block;">
|
| 999 |
+
#InnovateToElevate
|
| 1000 |
+
</span>
|
| 1001 |
+
</div>
|
| 1002 |
+
</div>
|
| 1003 |
+
</div>
|
| 1004 |
""")
|
| 1005 |
|
| 1006 |
# ===== MODEL INFORMATION =====
|
|
|
|
| 1048 |
- Containment-based filtering (boxes inside other boxes)
|
| 1049 |
- High-overlap cross-class suppression
|
| 1050 |
- Confidence-based quality assessment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1051 |
""")
|
| 1052 |
|
| 1053 |
# ===== EVENT BINDINGS =====
|
|
|
|
| 1090 |
gr.Markdown("""
|
| 1091 |
**Try these configurations for common scenarios:**
|
| 1092 |
|
| 1093 |
+
1. **Single clear object (like fire extinguisher):**
|
| 1094 |
- Confidence: 0.40, IoU: 0.50, TTA: β
, Ensemble: β, Size: 640px
|
| 1095 |
|
| 1096 |
2. **Multiple small objects:**
|
|
|
|
| 1103 |
- Confidence: 0.30, IoU: 0.50, TTA: β
, Enhancement: β
, Size: 800px
|
| 1104 |
""")
|
| 1105 |
|
| 1106 |
+
# ===== FOOTER =====
|
| 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;">
|
| 1111 |
+
Powered by <strong>TechXNinjas</strong> | PARANOX 2.0 Hackathon Project
|
| 1112 |
+
</p>
|
| 1113 |
+
<p style="opacity: 0.8; margin: 10px 0;">
|
| 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;">
|
| 1118 |
+
β οΈ AI-Powered Tool β’ Always verify critical detections manually<br>
|
| 1119 |
+
Made with β€οΈ for safety and security applications
|
| 1120 |
+
</p>
|
| 1121 |
+
</div>
|
| 1122 |
+
</div>
|
| 1123 |
+
""")
|
| 1124 |
+
|
| 1125 |
|
| 1126 |
# ==========================================================
|
| 1127 |
# LAUNCH APPLICATION
|
| 1128 |
# ==========================================================
|
| 1129 |
if __name__ == "__main__":
|
| 1130 |
print("\n" + "="*60)
|
| 1131 |
+
print("β‘ TechXNinjas - PARANOX 2.0")
|
| 1132 |
+
print("π Starting AI Safety Object Detector")
|
| 1133 |
print("="*60)
|
| 1134 |
print(f"π¦ Model: {MODEL_PATH}")
|
| 1135 |
print(f"π·οΈ Classes: {len(CLASS_NAMES)}")
|