alibidaran commited on
Commit
1763d5f
·
verified ·
1 Parent(s): f866f1b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ from ultralytics import YOLO
5
+ from PIL import Image
6
+ from ultralytics.utils.plotting import Annotator,colors
7
+
8
+
9
+ model = YOLO('Dental_model.pt') # Replace 'yolov8n.pt' with your model file if using a custom one
10
+
11
+ names=model.model.names
12
+ def detect_objects(image):
13
+ image1=image.copy()
14
+ results = model.predict(image)
15
+ whole=results[0].plot()
16
+ classes=results[0].boxes.cls.cpu().tolist()
17
+ boxes=results[0].boxes.xyxy.cpu()
18
+ annotator = Annotator(image, line_width=3)
19
+ annotator1=Annotator(image1, line_width=3)
20
+ for box,cls in zip(boxes,classes):
21
+ annotator.box_label(box, label=names[int(cls)], color=colors(int(cls)))
22
+ annotator1.box_label(box, label=None, color=colors(int(cls)))
23
+ return Image.fromarray(annotator.result()),Image.fromarray(annotator1.result())
24
+
25
+ # Gradio Interface
26
+ title = "YOLOv8 Object Detection"
27
+ description = "Upload an image to detect objects using a YOLOv8 model."
28
+
29
+ gradio_app =gr.Interface(fn=detect_objects,
30
+ inputs=gr.Image(type="pil"),
31
+ outputs=[gr.Image(type='pil', label="Dental Analysis"),
32
+ gr.Image(type='pil', label="Dental Analysis")])
33
+
34
+ if __name__=="__main__":
35
+ gradio_app.launch(server_name="0.0.0.0", server_port=7861, share=True, show_error=False)