Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
|
|
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def predict(image):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
app = gr.Interface(
|
| 12 |
-
fn
|
| 13 |
-
inputs
|
| 14 |
-
outputs
|
| 15 |
-
title
|
| 16 |
-
description
|
| 17 |
)
|
| 18 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
+
from ultralytics import YOLO
|
| 5 |
+
from PIL import Image
|
| 6 |
|
| 7 |
+
# Load YOLO model
|
| 8 |
+
model = YOLO("best.pt") # Ensure 'best.pt' is in the same directory
|
| 9 |
+
|
| 10 |
+
# Define prediction function
|
| 11 |
def predict(image):
|
| 12 |
+
# Perform YOLO detection
|
| 13 |
+
result = model.predict(source=image, imgsz=640, conf=0.25)
|
| 14 |
+
annotated_image = result[0].plot()
|
| 15 |
+
|
| 16 |
+
# Convert image from BGR to RGB
|
| 17 |
+
annotated_image = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
| 18 |
|
| 19 |
+
return annotated_image
|
| 20 |
+
|
| 21 |
+
# Gradio interface
|
| 22 |
app = gr.Interface(
|
| 23 |
+
fn=predict,
|
| 24 |
+
inputs=gr.Image(type="numpy", label="Upload an Image"),
|
| 25 |
+
outputs=gr.Image(type="numpy", label="Detected Tooth Cavity"),
|
| 26 |
+
title="Tooth Cavity Detection Using YOLO V10 by Pulastya 😎",
|
| 27 |
+
description="Upload a dental X-ray, and the YOLO V10 model will detect and annotate tooth decay."
|
| 28 |
)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
app.launch()
|