Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,20 @@ import gradio as gr
|
|
| 3 |
from ultralytics import YOLO
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
# Load YOLOv8 model
|
| 7 |
-
model = YOLO('
|
| 8 |
|
| 9 |
-
# Folder with test images
|
| 10 |
test_images_folder = 'test_images'
|
| 11 |
test_images = sorted(os.listdir(test_images_folder))
|
| 12 |
|
| 13 |
-
#
|
| 14 |
def predict_image(image_path):
|
| 15 |
results = model(image_path)
|
| 16 |
img_array = results[0].plot(conf=False, labels=True, boxes=True)
|
| 17 |
return Image.fromarray(img_array)
|
| 18 |
|
| 19 |
-
#
|
| 20 |
def run_prediction(uploaded_image, selected_image):
|
| 21 |
if uploaded_image is not None:
|
| 22 |
return predict_image(uploaded_image)
|
|
@@ -26,17 +26,17 @@ def run_prediction(uploaded_image, selected_image):
|
|
| 26 |
else:
|
| 27 |
return None
|
| 28 |
|
| 29 |
-
# Gradio
|
| 30 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 31 |
gr.Markdown("## 🦷 Dental Segmentation with YOLOv8")
|
| 32 |
-
gr.Markdown("Upload your own image or
|
| 33 |
|
| 34 |
with gr.Column():
|
| 35 |
uploaded_image = gr.Image(label="Upload your image (optional)", type="filepath")
|
| 36 |
-
selected_image = gr.Dropdown(choices=test_images, label="
|
| 37 |
|
| 38 |
-
gr.Markdown("### Prediction
|
| 39 |
-
output_image = gr.Image(label="Predicted
|
| 40 |
|
| 41 |
gr.Button("Run prediction").click(
|
| 42 |
fn=run_prediction,
|
|
|
|
| 3 |
from ultralytics import YOLO
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
+
# Load YOLOv8 model (make sure best.pt is in the same folder as this script)
|
| 7 |
+
model = YOLO('best.pt')
|
| 8 |
|
| 9 |
+
# Folder with example test images (must be inside your repo for HF Spaces)
|
| 10 |
test_images_folder = 'test_images'
|
| 11 |
test_images = sorted(os.listdir(test_images_folder))
|
| 12 |
|
| 13 |
+
# Predict using model
|
| 14 |
def predict_image(image_path):
|
| 15 |
results = model(image_path)
|
| 16 |
img_array = results[0].plot(conf=False, labels=True, boxes=True)
|
| 17 |
return Image.fromarray(img_array)
|
| 18 |
|
| 19 |
+
# Run prediction logic
|
| 20 |
def run_prediction(uploaded_image, selected_image):
|
| 21 |
if uploaded_image is not None:
|
| 22 |
return predict_image(uploaded_image)
|
|
|
|
| 26 |
else:
|
| 27 |
return None
|
| 28 |
|
| 29 |
+
# Gradio Interface
|
| 30 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 31 |
gr.Markdown("## 🦷 Dental Segmentation with YOLOv8")
|
| 32 |
+
gr.Markdown("Upload your own image or select a test image to run detection.")
|
| 33 |
|
| 34 |
with gr.Column():
|
| 35 |
uploaded_image = gr.Image(label="Upload your image (optional)", type="filepath")
|
| 36 |
+
selected_image = gr.Dropdown(choices=test_images, label="Or choose a test image")
|
| 37 |
|
| 38 |
+
gr.Markdown("### 📸 Prediction Output")
|
| 39 |
+
output_image = gr.Image(label="Predicted Output")
|
| 40 |
|
| 41 |
gr.Button("Run prediction").click(
|
| 42 |
fn=run_prediction,
|