S15-YOLOV9 / app.py
Shivdutta's picture
Upload 8 files
6619af4 verified
raw
history blame
3.35 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 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 video file and detect vehicles present in the video.
Inferencing is done using CPU therefore it takes more time.
"""
)
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)]
gr.Markdown("## Examples")
with gr.Row():
gr.Examples([
'cut_a_2.mp4',
'cut_b_1.mp4','tresa.mp4'],
inputs=img_input, fn=inference)
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(label="Output Image",width=640, height=640)]
gr.Markdown("## Examples")
with gr.Row():
gr.Examples([
'rohan.jpg',
'lamborghini-aventador-2932196_1280.jpg',
'0KL1ICR33YYZ.jpg',
'0RVD53V60NOM.jpg',
'0RW4I2NTAH8K.jpg',
'1CSLEJ2UJD3G.jpg',
'1E4CD5K13UXO.jpg',
'2.jpg',
'truck.jpg',
'3BXRTQZ70A7M.jpg',
'3GVLVIQ2J4P2.jpg',
'3RIYE11PE0VK.jpg',
'4AS6VDRS3Y07.jpg',
'4DM206U83T3B.jpg',
'05U2U2R2K6DN.jpg',
'6LBV93O0MWUY.jpg',
'6MFW23QQFW3E.jpg',
'6V4OYHB47QOX.jpg',
'6VOUS49LKRLI.jpg',
'6VOUS49LKRLI.jpg',
'7L1KFQDNLCBY.jpg',
'23BNPRMYV2RT.jpg',
'24IHCQ74TBML.jpg',
'38EE8ZBTSGD1.jpg',
'05U2U2R2K6DN.jpg',
'0KL1ICR33YYZ.jpg'
],
inputs=img_input, fn=inference)
image_button = gr.Button("Predict")
image_button.click(inference, inputs=img_input, outputs=pred_outputs)
demo.launch(share=True)