File size: 1,221 Bytes
67a2e99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import numpy as np
import cv2 
import os,glob
import json

with gr.Blocks() as demo:
    video_upload = gr.UploadButton(label="Upload the Video", file_types=["video"])
    slider = gr.Slider(maximum=200,interactive=True,steps=1)
    frames = []
    def get_frame(video):
        frames.clear()
        cap = cv2.VideoCapture(video.name)
        i = 0
        for i in range(201):
            ret, frame = cap.read()
            if ret == False:
                break
            frames.append(frame)
            i += 1
        cap.release()
        cv2.destroyAllWindows()
    video_upload.upload(fn=get_frame, inputs=[video_upload])
    def return_frame(index):
        img = frames[index]
        return img
    slider.change(return_frame,slider,gr.Image(shape=(1280, 720),type="numpy"))    
    question = gr.Textbox(label="Question")
    model_type = gr.CheckboxGroup(["SurgGPT","LCGN"],label="Model Choice")
    answer = gr.Textbox(label="Answer")
    predict = gr.Button(value="Predict")
    def predict_ans(index,question,model_choice):
        return "hi"
    predict.click(fn=predict_ans,inputs=[slider,question,model_type],outputs=[answer])
    
if __name__ == "__main__":
    demo.launch()