Dental_Analysis / app.py
alibidaran's picture
Update app.py
6fde9b5 verified
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()