Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ import os
|
|
4 |
import json
|
5 |
import rembg
|
6 |
import cv2
|
|
|
|
|
7 |
|
8 |
load_js = """
|
9 |
function(text_input, url_params) {
|
@@ -26,8 +28,43 @@ def rem_cv(inp):
|
|
26 |
fgmask = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel)
|
27 |
yield (fgmask)
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def rem_bg(inp):
|
|
|
|
|
|
|
31 |
out = rem_bg()
|
32 |
|
33 |
|
@@ -76,7 +113,12 @@ with gr.Blocks() as app:
|
|
76 |
with gr.Column():
|
77 |
outp_vid=gr.Video()
|
78 |
with gr.Column():
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
80 |
with gr.Tab("Rem BG"):
|
81 |
with gr.Row():
|
82 |
with gr.Column():
|
@@ -84,11 +126,13 @@ with gr.Blocks() as app:
|
|
84 |
in_vid=gr.Video()
|
85 |
with gr.Column():
|
86 |
#rem_vid=gr.Video()
|
87 |
-
rem_vid=gr.
|
88 |
with gr.Row(visible=False):
|
89 |
text_input=gr.Textbox()
|
90 |
text_output=gr.Textbox()
|
91 |
url_params=gr.JSON()
|
|
|
|
|
92 |
rem_btn.click(rem_cv,in_vid,rem_vid)
|
93 |
go_btn.click(dl,inp_url,[outp_vid,in_vid,outp_file])
|
94 |
app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
|
|
|
4 |
import json
|
5 |
import rembg
|
6 |
import cv2
|
7 |
+
import uuid
|
8 |
+
uid=uuid.uuid4()
|
9 |
|
10 |
load_js = """
|
11 |
function(text_input, url_params) {
|
|
|
28 |
fgmask = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel)
|
29 |
yield (fgmask)
|
30 |
|
31 |
+
def load_video(vid):
|
32 |
+
new_video_in = str(vid)
|
33 |
+
capture = cv2.VideoCapture(new_video_in)
|
34 |
+
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
35 |
+
tmp_frame='1'
|
36 |
+
capture.release()
|
37 |
+
return frame_count
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
def capture_function(vid=None):
|
42 |
+
if vid==None:
|
43 |
+
vid=img_file
|
44 |
+
new_video_in = str(vid)
|
45 |
+
capture = cv2.VideoCapture(new_video_in)
|
46 |
+
fbox=[]
|
47 |
+
cnt=0
|
48 |
+
frame_count1= int(frame_count)
|
49 |
+
for i in range(int(frame_count1)):
|
50 |
+
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
51 |
+
ret, frame_f = capture.read(i)
|
52 |
+
frame_ff = cv2.cvtColor(frame_f, cv2.COLOR_BGR2RGB)
|
53 |
|
54 |
+
fbox.append(frame_ff)
|
55 |
+
|
56 |
+
capture.set(cv2.CAP_PROP_POS_FRAMES, int(frame_count)-1)
|
57 |
+
ret, frame_f = capture.read()
|
58 |
+
frame_ff = cv2.cvtColor(frame_f, cv2.COLOR_BGR2RGB)
|
59 |
+
fbox.append(frame_ff)
|
60 |
+
capture.release()
|
61 |
+
return fbox
|
62 |
+
|
63 |
+
|
64 |
def rem_bg(inp):
|
65 |
+
cap = cv2.VideoCapture(f'{inp}')
|
66 |
+
ret, frame = cap.read()
|
67 |
+
|
68 |
out = rem_bg()
|
69 |
|
70 |
|
|
|
113 |
with gr.Column():
|
114 |
outp_vid=gr.Video()
|
115 |
with gr.Column():
|
116 |
+
frame_count=gr.Textbox()
|
117 |
+
outp_file=gr.Files()
|
118 |
+
with gr.Tab("Frames"):
|
119 |
+
frame_btn = gr.Button("Get Frames")
|
120 |
+
frame_gal = gr.Gallery()
|
121 |
+
|
122 |
with gr.Tab("Rem BG"):
|
123 |
with gr.Row():
|
124 |
with gr.Column():
|
|
|
126 |
in_vid=gr.Video()
|
127 |
with gr.Column():
|
128 |
#rem_vid=gr.Video()
|
129 |
+
rem_vid=gr.Gallery()
|
130 |
with gr.Row(visible=False):
|
131 |
text_input=gr.Textbox()
|
132 |
text_output=gr.Textbox()
|
133 |
url_params=gr.JSON()
|
134 |
+
outp_vid.change(load_video,outp_vid,frame_count)
|
135 |
+
frame_btn.click(capture_function,[outp_vid,frame_count],frame_gal)
|
136 |
rem_btn.click(rem_cv,in_vid,rem_vid)
|
137 |
go_btn.click(dl,inp_url,[outp_vid,in_vid,outp_file])
|
138 |
app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
|