Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from ultralytics import YOLO
|
| 4 |
-
import numpy as np
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
model = YOLO("best (2).pt")
|
| 8 |
|
| 9 |
-
# Prediction function
|
| 10 |
def detect_teeth(image):
|
| 11 |
-
results = model.predict(image
|
| 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 |
-
#
|
| 19 |
-
output_img = r.plot()
|
| 20 |
return Image.fromarray(output_img)
|
| 21 |
|
| 22 |
# Gradio interface
|
|
@@ -24,8 +21,8 @@ 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
|
| 28 |
-
description="Upload a dental X-ray to see segmentation
|
| 29 |
)
|
| 30 |
|
| 31 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from ultralytics import YOLO
|
|
|
|
| 4 |
|
| 5 |
+
# Load the model with original name
|
| 6 |
model = YOLO("best (2).pt")
|
| 7 |
|
|
|
|
| 8 |
def detect_teeth(image):
|
| 9 |
+
results = model.predict(image)
|
| 10 |
|
|
|
|
| 11 |
r = results[0]
|
| 12 |
if r.masks is not None:
|
| 13 |
r.masks.data = (r.masks.data > 0.3).float()
|
| 14 |
|
| 15 |
+
# Render without confidence scores or labels
|
| 16 |
+
output_img = r.plot(conf=False, labels=False, boxes=True)
|
| 17 |
return Image.fromarray(output_img)
|
| 18 |
|
| 19 |
# Gradio interface
|
|
|
|
| 21 |
fn=detect_teeth,
|
| 22 |
inputs=gr.Image(type="pil", label="Upload Dental X-ray"),
|
| 23 |
outputs=gr.Image(type="pil", label="Detection Result"),
|
| 24 |
+
title="Dental Segmentation App",
|
| 25 |
+
description="Upload a dental X-ray to see the segmentation result using YOLOv8."
|
| 26 |
)
|
| 27 |
|
| 28 |
interface.launch()
|