Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
+
import uuid
|
6 |
+
|
7 |
+
def inference(input_img):
|
8 |
+
temp = uuid.uuid4()
|
9 |
+
shell = f"python yolov9/detect.py --source {input_img} --img 640 --device cpu --weights yolov9/runs/train/exp/weights/best.pt --name {temp}"
|
10 |
+
os.system(shell)
|
11 |
+
return f"yolov9/runs/detect/{temp}/{input_img.split('/')[-1]}"
|
12 |
+
|
13 |
+
def inference_video(input_img):
|
14 |
+
org_img = input_img
|
15 |
+
return input_img
|
16 |
+
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
gr.Markdown(
|
19 |
+
"""
|
20 |
+
# Vehicle detection using Yolo-v9
|
21 |
+
Upload the vehicle image or video for detection
|
22 |
+
"""
|
23 |
+
)
|
24 |
+
|
25 |
+
with gr.Tab("Video"):
|
26 |
+
gr.Markdown(
|
27 |
+
"""
|
28 |
+
Upload video mp4 file and detect the count of vehicles passing by
|
29 |
+
"""
|
30 |
+
)
|
31 |
+
gr.Markdown(
|
32 |
+
"""
|
33 |
+
Upload image file and detect vehicles present in the image
|
34 |
+
"""
|
35 |
+
)
|
36 |
+
with gr.Row():
|
37 |
+
img_input = [gr.Video(label="Input Image",width=300, height=300)]
|
38 |
+
pred_outputs = [gr.Video(label="Output Image",width=300, height=300)]
|
39 |
+
|
40 |
+
image_button = gr.Button("Predict")
|
41 |
+
image_button.click(inference, inputs=img_input, outputs=pred_outputs)
|
42 |
+
|
43 |
+
with gr.Tab("Image"):
|
44 |
+
gr.Markdown(
|
45 |
+
"""
|
46 |
+
Upload image file and detect vehicles present in the image
|
47 |
+
"""
|
48 |
+
)
|
49 |
+
with gr.Row():
|
50 |
+
img_input = [gr.Image(type="filepath",label="Input Image",width=300, height=300)]
|
51 |
+
pred_outputs = [gr.Image(label="Output Image",width=640, height=640)]
|
52 |
+
|
53 |
+
image_button = gr.Button("Predict")
|
54 |
+
image_button.click(inference, inputs=img_input, outputs=pred_outputs)
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
demo.launch(share=True)
|