Omnibus commited on
Commit
7022cc6
·
1 Parent(s): fbaf836

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -2,7 +2,9 @@ import gradio as gr
2
  import yt_dlp
3
  import os
4
  import json
5
- import backgroundremover
 
 
6
  load_js = """
7
  function(text_input, url_params) {
8
  console.log(text_input, url_params);
@@ -11,8 +13,26 @@ function(text_input, url_params) {
11
  return [text_input, url_params]
12
  }
13
  """
 
 
 
 
 
 
 
 
 
 
 
 
14
 
 
15
  def rem_bg(inp):
 
 
 
 
 
16
  #transparent background .mov
17
  #os.system(f'backgroundremover -i "{inp}" -tv -o "{inp}.mov"')
18
  #video video to be overlayed output
@@ -68,7 +88,7 @@ with gr.Blocks() as app:
68
  text_input=gr.Textbox()
69
  text_output=gr.Textbox()
70
  url_params=gr.JSON()
71
- rem_btn.click(rem_bg,in_vid,rem_vid)
72
  go_btn.click(dl,inp_url,[outp_vid,in_vid,outp_file])
73
  app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
74
  app.launch()
 
2
  import yt_dlp
3
  import os
4
  import json
5
+ import rembg
6
+ import cv2
7
+
8
  load_js = """
9
  function(text_input, url_params) {
10
  console.log(text_input, url_params);
 
13
  return [text_input, url_params]
14
  }
15
  """
16
+ def rem_cv(inp):
17
+ cv2cap = cv2.VideoCapture(f'{inp}')
18
+
19
+ kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))
20
+ fgbg = cv2.bgsegm.createBackgroundSubtractorGMG()
21
+
22
+ while True():
23
+ ret, frame = cap.read()
24
+
25
+ fgmask = fgbg.apply(frame)
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
+
34
+
35
+ def rem_bg_og(inp):
36
  #transparent background .mov
37
  #os.system(f'backgroundremover -i "{inp}" -tv -o "{inp}.mov"')
38
  #video video to be overlayed output
 
88
  text_input=gr.Textbox()
89
  text_output=gr.Textbox()
90
  url_params=gr.JSON()
91
+ rem_btn.click(rem_cv,in_vid,rem_vid)
92
  go_btn.click(dl,inp_url,[outp_vid,in_vid,outp_file])
93
  app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
94
  app.launch()