File size: 1,751 Bytes
6e11613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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]}"

def inference_video(input_img):
    org_img = input_img
    return input_img

with gr.Blocks() as demo:
    gr.Markdown(
        """
        # Vehicle detection using Yolo-v9
        Upload the vehicle image or video for detection
        """
    )

    with gr.Tab("Video"):
        gr.Markdown(
            """
            Upload video mp4 file and detect the count of vehicles passing by
            """
        )
        gr.Markdown(
            """
            Upload image file and detect vehicles present in the image
            """
        )
        with gr.Row():
            img_input = [gr.Video(label="Input Image",width=300, height=300)]
            pred_outputs = [gr.Video(label="Output Image",width=300, height=300)]
        
        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)]
        
        image_button = gr.Button("Predict")
        image_button.click(inference, inputs=img_input, outputs=pred_outputs)



demo.launch(share=True)