File size: 1,678 Bytes
32bee2a
3d4164f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e9193b
4b558b8
3d4164f
4b558b8
3d4164f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv211
import gradio as gr
import validators
from cap_from_youtube import cap_from_youtube

import video_detection
from video_detection import video_detection


def preprocess_input(input):
    # if not input:
    #     cap = cv2.VideoCapture(0)
    #     yield from video_detection(cap)
    if validators.url(input):
        if 'youtu' in input:
            cap = cap_from_youtube(input, resolution='720p')
            yield from video_detection(cap)
        else:
            print("Invalid URL")
    else:
        cap = cv2.VideoCapture(input)
        yield from video_detection(cap)

# gradio interface
input_video = gr.Video(label="Input Video")
input_url = gr.Textbox(label="Input URL", placeholder="Enter URL")
output_frames_1 = gr.Image(label="Output Frames")
output_video_file_1 = gr.Video(label="Output video", streaming=True, autoplay=True)
output_frames_2 = gr.Image(label="Output Frames")
output_video_file_2 = gr.Video(label="Output video", streaming=True, autoplay=True)
# sample_video=r'sample/car.mp4'

file_tab = gr.Interface(
    fn=preprocess_input,
    inputs=[input_video],
    outputs=[output_frames_1, output_video_file_1],
    title=f"Завантажте файл для розпізнавання",
    allow_flagging="never",
    examples=[["car.mp4"]],
)

url_tab = gr.Interface(
    fn=preprocess_input,
    inputs=[input_url],
    outputs=[output_frames_2, output_video_file_2],
    title=f"Введіть URL Youtube відео для розпізнавання",
    allow_flagging="never",
    examples=[["car.mp4"]],
)

app = gr.TabbedInterface([file_tab, url_tab], ["Завантажити файл", "Ввести URL"])

app.launch()