File size: 1,493 Bytes
9336d9f
72aec6b
99a7282
9336d9f
7d1e2ec
a22da3a
 
 
 
5736611
a22da3a
 
2ba6ac8
5dc50e0
5736611
2ba6ac8
 
3594539
83214d4
2ba6ac8
 
 
 
8d0107b
9336d9f
92e66d1
a8eb6f2
0918b52
a8eb6f2
0918b52
 
ff5b9c0
2ba6ac8
0918b52
ff5b9c0
0918b52
 
 
2ba6ac8
0279e71
ff5b9c0
 
 
 
 
 
 
 
1e4d22a
2fa0a0a
a8eb6f2
0279e71
346e501
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 gradio as gr
import time
import os

from mhr.predict_tools import MHRStoneRecognizeMgr, MHRVedioCuter

mgr = MHRStoneRecognizeMgr(
    whole_pkl = "./whole_model.pkl",
    hole_pkl = "./hole_model.pkl",
    vedio_cutter = None,
)

def greet(v, speed_ratio, debug, progress=gr.Progress(track_tqdm=True)):
    print("v:", v)
    result = []
    ret_offset = -3 if debug else -2
    cuter = MHRVedioCuter(speed_ratio)
    for data in progress.tqdm(cuter.iter(v)):
        ok, ret = mgr.recognize_image(data)
        if not ok : continue
        print(ret[-2:])
        if len(result)>0 and result[-1][-2:] == ret[-2:]: continue
        result.append(ret[ret_offset:])
    return "".join([ str(item)+"\n" for item in result ])


with gr.Blocks() as demo:
    
    with gr.Row():
        with gr.Column():
            input_video = gr.Video()
            input_speed = gr.Slider(1, 60, value=5, label="speed_ratio")
            input_debug = gr.Checkbox(label="debug")
            btn = gr.Button(value="Submit")
            
        with gr.Column(): 
            output_res = gr.Textbox(label="result")
            
    input = [input_video, input_speed, input_debug]
    output = [output_res]

    gr.Examples(
        examples=[[os.path.join(os.path.dirname(__file__), "example/test.mp4")]],
        inputs=input, 
        outputs=output,
        fn=greet,
        cache_examples=False,
    )
    
    btn.click(greet, inputs=input, outputs=output)
    

demo.queue().launch(debug=True)