ajeetsraina commited on
Commit
b03de73
·
verified ·
1 Parent(s): 69c6304

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -3
app.py CHANGED
@@ -1,16 +1,28 @@
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:
@@ -20,20 +32,38 @@ def analyze_xray(image):
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
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  from PIL import Image
4
+ from huggingface_hub import hf_hub_download
5
 
6
+ # Download model from Hugging Face
7
+ print("Downloading model from Hugging Face...")
8
+ model_path = hf_hub_download(
9
+ repo_id="ajeetsraina/clinical-dental-pathology-detector",
10
+ filename="models/dental_pathology_detector.pt"
11
+ )
12
+ print(f"Model downloaded to: {model_path}")
13
+
14
+ # Load model
15
+ model = YOLO(model_path)
16
 
17
  def analyze_xray(image):
18
  if image is None:
19
  return None, "Please upload an X-ray image"
20
+
21
  results = model.predict(image, conf=0.25)
22
  annotated = results[0].plot()
23
  annotated_pil = Image.fromarray(annotated)
24
  detections = results[0].boxes
25
+
26
  if len(detections) == 0:
27
  report = "✅ No significant pathologies detected"
28
  else:
 
32
  if cls_name not in class_counts:
33
  class_counts[cls_name] = 0
34
  class_counts[cls_name] += 1
35
+
36
  report = f"**Total Findings:** {len(detections)}\n\n"
37
  for cls_name, count in class_counts.items():
38
  emoji = {"Cavity": "⚠️", "Fillings": "✅", "Implant": "🦷", "Impacted Tooth": "⚠️"}.get(cls_name, "ℹ️")
39
  report += f"{emoji} **{cls_name}**: {count} detected\n"
40
+
41
  return annotated_pil, report
42
 
43
  demo = gr.Interface(
44
  fn=analyze_xray,
45
  inputs=gr.Image(type="pil", label="Upload Dental X-ray"),
46
+ outputs=[
47
+ gr.Image(type="pil", label="Analyzed X-ray"),
48
+ gr.Markdown(label="Clinical Report")
49
+ ],
50
  title="🦷 Clinical Dental Pathology Detector",
51
+ description="Upload dental X-ray to detect cavities, fillings, implants, and impacted teeth. **98.9% mAP@50 accuracy**",
52
+ article="Model: [ajeetsraina/clinical-dental-pathology-detector](https://huggingface.co/ajeetsraina/clinical-dental-pathology-detector)"
53
  )
54
 
55
  demo.launch()
56
+ ```
57
+
58
+ ---
59
 
60
+ ## **📝 Update requirements.txt**
61
 
62
+ Also update your `requirements.txt`:
63
+ ```
64
+ gradio
65
+ ultralytics
66
+ pillow
67
+ torch
68
+ opencv-python-headless
69
+ huggingface_hub