Spaces:
Running
Running
File size: 1,381 Bytes
1763d5f 2abbad0 1763d5f 6fde9b5 1763d5f 2abbad0 1763d5f 2c4c794 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
from ultralytics import YOLO
from PIL import Image
from ultralytics import YOLO
from PIL import Image
from ultralytics.utils.plotting import Annotator,colors
import glob
model = YOLO('Dental_model.pt') # Replace 'yolov8n.pt' with your model file if using a custom one
pic_files=glob.glob('*.jpg')
names=model.model.names
def detect_objects(image):
image1=image.copy()
results = model.predict(image)
whole=results[0].plot()
classes=results[0].boxes.cls.cpu().tolist()
boxes=results[0].boxes.xyxy.cpu()
annotator = Annotator(image, line_width=3)
annotator1=Annotator(image1, line_width=3)
for box,cls in zip(boxes,classes):
annotator.box_label(box, label=names[int(cls)], color=colors(int(cls)))
annotator1.box_label(box, label=None, color=colors(int(cls)))
return Image.fromarray(annotator.result()),Image.fromarray(annotator1.result())
# Gradio Interface
title = "YOLOv8 Object Detection"
description = "Upload an image to detect objects using a YOLOv8 model."
gradio_app =gr.Interface(fn=detect_objects,
inputs=gr.Image(type="pil"),
outputs=[gr.Image(type='pil', label="Dental Analysis"),
gr.Image(type='pil', label="Dental Analysis")],
examples=pic_files)
if __name__=="__main__":
gradio_app.launch() |