lalith
commited on
Commit
·
67a2e99
1
Parent(s):
d8c497b
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import cv2
|
4 |
+
import os,glob
|
5 |
+
import json
|
6 |
+
|
7 |
+
with gr.Blocks() as demo:
|
8 |
+
video_upload = gr.UploadButton(label="Upload the Video", file_types=["video"])
|
9 |
+
slider = gr.Slider(maximum=200,interactive=True,steps=1)
|
10 |
+
frames = []
|
11 |
+
def get_frame(video):
|
12 |
+
frames.clear()
|
13 |
+
files = glob.glob('frames/*')
|
14 |
+
for f in files:
|
15 |
+
os.remove(f)
|
16 |
+
cap = cv2.VideoCapture(video.name)
|
17 |
+
i = 0
|
18 |
+
for i in range(201):
|
19 |
+
ret, frame = cap.read()
|
20 |
+
if ret == False:
|
21 |
+
break
|
22 |
+
frames.append(frame)
|
23 |
+
# cv2.imwrite("frames/frame_{}.jpeg".format(i),frame)
|
24 |
+
i += 1
|
25 |
+
cap.release()
|
26 |
+
cv2.destroyAllWindows()
|
27 |
+
video_upload.upload(fn=get_frame, inputs=[video_upload])
|
28 |
+
def return_frame(index):
|
29 |
+
# img = cv2.imread("frames/frame_{}.jpeg".format(index))
|
30 |
+
img = frames[index]
|
31 |
+
return img
|
32 |
+
slider.change(return_frame,slider,gr.Image(shape=(1280, 720),type="numpy"))
|
33 |
+
question = gr.Textbox(label="Question")
|
34 |
+
model_type = gr.CheckboxGroup(["SurgGPT","LCGN"],label="Model Choice")
|
35 |
+
answer = gr.Textbox(label="Answer")
|
36 |
+
predict = gr.Button(value="Predict")
|
37 |
+
def predict_ans(index,question,model_choice):
|
38 |
+
return "hi"
|
39 |
+
predict.click(fn=predict_ans,inputs=[slider,question,model_type],outputs=[answer])
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
demo.launch()
|