Import app.py from GitHub
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
import PIL
|
| 4 |
+
|
| 5 |
+
model = YOLO("yolov8n.pt")
|
| 6 |
+
|
| 7 |
+
def predict_image(img):
|
| 8 |
+
results = model.predict(source=img)
|
| 9 |
+
annotated_img = results[0].plot()
|
| 10 |
+
annotated_img = PIL.Image.fromarray(annotated_img[...,::-1])
|
| 11 |
+
|
| 12 |
+
return annotated_img
|
| 13 |
+
|
| 14 |
+
gradio_app = gr.Interface(
|
| 15 |
+
fn=predict_image,
|
| 16 |
+
inputs=gr.Image(type="pil"),
|
| 17 |
+
outputs=gr.Image(type="pil"),
|
| 18 |
+
title="Object Detection",
|
| 19 |
+
examples=["dog.webp", "zidane.jpg", "huggingface.png"]
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
gradio_app.launch()
|