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()