amirgame197 commited on
Commit
172a03a
1 Parent(s): 63b8881

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -22
app.py CHANGED
@@ -6,37 +6,42 @@ import numpy as np
6
  from PIL import Image
7
  from transparent_background import Remover
8
 
9
- remover = Remover()
10
 
11
- @spaces.GPU
12
- def doo(video):
13
- cap = cv2.VideoCapture(video)
14
- fps = cap.get(cv2.CAP_PROP_FPS)
15
-
16
- writer = None
17
 
18
- processed_frames = 0
19
 
20
- while cap.isOpened():
21
- ret, frame = cap.read()
22
 
23
- if ret is False:
24
- break
 
 
 
25
 
26
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
27
- img = Image.fromarray(frame).convert('RGB')
28
 
29
- if writer is None:
30
- writer = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, img.size)
31
 
32
- processed_frames += 1
33
- print(f"Processing: {processed_frames}")
34
 
35
- out = remover.process(img, type='green')
36
- writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
37
 
38
- cap.release()
39
- writer.release()
 
 
 
 
 
40
  return 'output.mp4'
41
 
42
  iface = gr.Interface(fn=doo, inputs="video", outputs="video")
 
6
  from PIL import Image
7
  from transparent_background import Remover
8
 
9
+ #remover = Remover()
10
 
11
+ #@spaces.GPU
12
+ #def doo(video):
13
+ #cap = cv2.VideoCapture(video)
14
+ #fps = cap.get(cv2.CAP_PROP_FPS)
 
 
15
 
16
+ #writer = None
17
 
18
+ #processed_frames = 0
 
19
 
20
+ #while cap.isOpened():
21
+ # ret, frame = cap.read()
22
+ #
23
+ # if ret is False:
24
+ # break
25
 
26
+ # frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
27
+ # img = Image.fromarray(frame).convert('RGB')
28
 
29
+ # if writer is None:
30
+ # writer = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, img.size)
31
 
32
+ # processed_frames += 1
33
+ # print(f"Processing: {processed_frames}")
34
 
35
+ # out = remover.process(img, type='green')
36
+ # writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
37
 
38
+ #cap.release()
39
+ #writer.release()
40
+ #return 'output.mp4'
41
+
42
+ @spaces.GPU
43
+ def doo(video):
44
+ rembg.greenscreen(video, gpu=True, output="output.mp4", format="mp4", alpha=True, gpubatchsize=10)
45
  return 'output.mp4'
46
 
47
  iface = gr.Interface(fn=doo, inputs="video", outputs="video")