Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# from fastapi import FastAPI, File, UploadFile
|
2 |
+
# from fastapi.responses import StreamingResponse
|
3 |
+
from io import BytesIO
|
4 |
+
import cv2
|
5 |
+
import numpy as np
|
6 |
+
import gradio as gr
|
7 |
+
from ultralytics import YOLO
|
8 |
+
|
9 |
+
# Inicializar o modelo YOLO
|
10 |
+
model = YOLO("/content/best.pt")
|
11 |
+
|
12 |
+
# Definir a função para detecção de objetos
|
13 |
+
def detect_objects(image):
|
14 |
+
# Realizar a detecção de objetos com YOLOv8
|
15 |
+
detections = model.predict(image)
|
16 |
+
# Renderizar as detecções na imagem
|
17 |
+
rendered_image = detections.render()
|
18 |
+
return rendered_image
|
19 |
+
|
20 |
+
# Criar a interface Gradio
|
21 |
+
app = gr.Interface(
|
22 |
+
fn=detect_objects,
|
23 |
+
inputs="image",
|
24 |
+
outputs="image",
|
25 |
+
title="YOLOv8 Object Detection",
|
26 |
+
description="Detect objects in images using YOLOv8.",
|
27 |
+
)
|
28 |
+
|
29 |
+
# Executar o aplicativo
|
30 |
+
app.launch()
|