Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
#ONLY yolov5 single input and output
|
2 |
-
import gradio as gr
|
3 |
-
from ultralyticsplus import YOLO
|
4 |
-
#import yolov5
|
5 |
-
from PIL import Image
|
6 |
-
|
7 |
-
# Load your model
|
8 |
-
# model = yolov5.load('MvitHYF/cocoaseedyolov5mvit')
|
9 |
-
model_path = "/Users/heartties/Desktop/yolo-safety-env/code/v5cocoaseedmvit2024space/best.pt"
|
10 |
-
model = YOLO(model_path)
|
11 |
-
model.conf = 0.40
|
12 |
-
model.iou = 0.45
|
13 |
-
model.agnostic = True
|
14 |
-
model.multi_label = False
|
15 |
-
model.max_det = 100
|
16 |
-
# model.overrides['conf'] = 0.25 # NMS confidence threshold
|
17 |
-
# model.overrides['iou'] = 0.45 # NMS IoU threshold
|
18 |
-
# model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
19 |
-
# model.overrides['max_det'] = 1000 # maximum number of detections per image
|
20 |
-
|
21 |
-
#css = ".output_image {height: 40rem !important; width: 100% !important;}"
|
22 |
-
|
23 |
-
def predict(input_image):
|
24 |
-
try:
|
25 |
-
# Perform inference
|
26 |
-
results = model(input_image, size=(1920), augment=True)
|
27 |
-
|
28 |
-
# Convert result image with bounding boxes to PIL format for Gradio output
|
29 |
-
result_image = Image.fromarray(results.render()[0])
|
30 |
-
|
31 |
-
return result_image
|
32 |
-
|
33 |
-
except Exception as e:
|
34 |
-
return f"Error: {str(e)}"
|
35 |
-
|
36 |
-
# Set up Gradio interface
|
37 |
-
interface = gr.Interface(
|
38 |
-
fn=predict,
|
39 |
-
inputs=gr.Image(type="pil", label="Upload an Image1"),
|
40 |
-
outputs=gr.Image(type="pil", label="Result1"),
|
41 |
-
#css = css,
|
42 |
-
title="Object Detection using YOLOv5",
|
43 |
-
description="Upload an image to detect objects using the YOLOv5 model"
|
44 |
-
)
|
45 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|