-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (48 loc) · 1.53 KB
/
main.py
File metadata and controls
59 lines (48 loc) · 1.53 KB
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 warnings
from glob import glob
import gradio as gr
from src.inference.inference_yolo_ncnn import NCNN_MODEL
from src.utils import clear_output_directory
warnings.filterwarnings('ignore')
SAMPLE_VIDEO_NAME = 'test_2sec'
SAMPLE_IMAGE_NAME = 'sample_2'
def process_video(video):
clear_output_directory()
NCNN_MODEL.simple_predict(video, save=True)
output_files = glob('runs/detect/predict/*.avi')
if output_files:
return output_files[0]
else:
return None
def process_image(image):
clear_output_directory()
NCNN_MODEL.simple_predict(image, save=True)
output_files = glob('runs/detect/predict/*.jpg')
if output_files:
return output_files[0]
else:
return None
with gr.Blocks() as demo:
gr.Markdown("# Detection of Road Signs")
gr.Markdown("To start the process, upload a video (mp4) or an image (jpg) file.")
gr.Markdown("### Note: Run this on a local device.")
video_interface = gr.Interface(
fn=process_video,
inputs=gr.Video(),
outputs="playable_video",
examples=[f"samples/video/{SAMPLE_VIDEO_NAME}.mov"],
cache_examples=True,
live=True,
theme="huggingface",
title="Video Processing"
)
image_interface = gr.Interface(
fn=process_image,
inputs=gr.Image(type="pil"),
outputs="image",
examples=[f"samples/images/{SAMPLE_IMAGE_NAME}.jpg"],
theme="huggingface",
title="Image Processing"
)
if __name__ == "__main__":
demo.launch(share=True)