Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Load your model
|
| 7 |
+
model = YOLO("best (2).pt")
|
| 8 |
+
|
| 9 |
+
# Prediction function
|
| 10 |
+
def detect_teeth(image):
|
| 11 |
+
results = model.predict(image, conf=0.26)
|
| 12 |
+
|
| 13 |
+
# Optional post-processing
|
| 14 |
+
r = results[0]
|
| 15 |
+
if r.masks is not None:
|
| 16 |
+
r.masks.data = (r.masks.data > 0.3).float()
|
| 17 |
+
|
| 18 |
+
# Create segmented image with bounding boxes and masks
|
| 19 |
+
output_img = r.plot()
|
| 20 |
+
return Image.fromarray(output_img)
|
| 21 |
+
|
| 22 |
+
# Gradio interface
|
| 23 |
+
interface = gr.Interface(
|
| 24 |
+
fn=detect_teeth,
|
| 25 |
+
inputs=gr.Image(type="pil", label="Upload Dental X-ray"),
|
| 26 |
+
outputs=gr.Image(type="pil", label="Detection Result"),
|
| 27 |
+
title="Dental X-ray Detection",
|
| 28 |
+
description="Upload a dental X-ray to see segmentation and detection results using YOLOv8."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
interface.launch()
|