S15-YOLOV9 / app.py
Shivdutta's picture
Update app.py
0c72267 verified
raw
history blame
No virus
1.71 kB
import gradio as gr
from PIL import Image
import numpy as np
import os
import uuid
def inference(input_img):
temp = uuid.uuid4()
shell = f"python yolov9/detect.py --source {input_img} --img 640 --device cpu --weights yolov9/runs/train/exp/weights/best.pt --name {temp}"
os.system(shell)
return Image.open(f"yolov9/runs/detect/{temp}/{input_img.split('/')[-1]}")
#return "yolov9/runs/detect/f807164a-496b-413c-bb47-f5daf8803dcd/cut_a_1.mp4"
def inference_video(input_img):
org_img = input_img
return input_img
with gr.Blocks() as demo:
gr.Markdown(
"""
# Vehicle detection using Yolo-v9
"""
)
with gr.Tab("Video"):
gr.Markdown(
"""
Upload image file and detect vehicles present in the image
"""
)
with gr.Row():
img_input = [gr.PlayableVideo(label="Input Image", autoplay=True, width=300, height=300)]
pred_outputs = [gr.PlayableVideo(label="Output Image",width=640, autoplay=True, height=640)]
image_button = gr.Button("Predict")
image_button.click(inference, inputs=img_input, outputs=pred_outputs)
with gr.Tab("Image"):
gr.Markdown(
"""
Upload image file and detect vehicles present in the image
"""
)
with gr.Row():
img_input = [gr.Image(type="filepath",label="Input Image",width=300, height=300)]
pred_outputs = [gr.Image(type="pil",label="Output Image",width=640, height=640)]
image_button = gr.Button("Predict")
image_button.click(inference, inputs=img_input, outputs=pred_outputs)
demo.launch(share=True)