ajeetsraina commited on
Commit
f76fc70
·
verified ·
1 Parent(s): 52c3b8e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+
5
+ model = YOLO('ajeetsraina/clinical-dental-pathology-detector')
6
+
7
+ def analyze_xray(image):
8
+ if image is None:
9
+ return None, "Please upload an X-ray image"
10
+ results = model.predict(image, conf=0.25)
11
+ annotated = results[0].plot()
12
+ annotated_pil = Image.fromarray(annotated)
13
+ detections = results[0].boxes
14
+ if len(detections) == 0:
15
+ report = "✅ No significant pathologies detected"
16
+ else:
17
+ class_counts = {}
18
+ for box in detections:
19
+ cls_name = model.names[int(box.cls[0])]
20
+ if cls_name not in class_counts:
21
+ class_counts[cls_name] = 0
22
+ class_counts[cls_name] += 1
23
+ report = f"**Total Findings:** {len(detections)}\n\n"
24
+ for cls_name, count in class_counts.items():
25
+ emoji = {"Cavity": "⚠️", "Fillings": "✅", "Implant": "🦷", "Impacted Tooth": "⚠️"}.get(cls_name, "ℹ️")
26
+ report += f"{emoji} **{cls_name}**: {count} detected\n"
27
+ return annotated_pil, report
28
+
29
+ demo = gr.Interface(
30
+ fn=analyze_xray,
31
+ inputs=gr.Image(type="pil", label="Upload Dental X-ray"),
32
+ outputs=[gr.Image(type="pil", label="Analyzed X-ray"), gr.Markdown(label="Clinical Report")],
33
+ title="🦷 Clinical Dental Pathology Detector",
34
+ description="Upload dental X-ray to detect cavities, fillings, implants, and impacted teeth. **98.9% mAP@50**"
35
+ )
36
+
37
+ demo.launch()
38
+ ```
39
+
40
+ **Create `requirements.txt`:**
41
+ ```
42
+ gradio
43
+ ultralytics>=8.3.0
44
+ pillow
45
+ numpy
46
+ torch
47
+ torchvision
48
+ opencv-python-headless