amirgame197 commited on
Commit
ae8c232
1 Parent(s): b2c8d9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -12,7 +12,10 @@ torch.jit.script = lambda f: f
12
  from transparent_background import Remover
13
 
14
  @spaces.GPU()
15
- def doo(video, mode, progress=gr.Progress()):
 
 
 
16
  if mode == 'Fast':
17
  remover = Remover(mode='fast')
18
  else:
@@ -45,7 +48,7 @@ def doo(video, mode, progress=gr.Progress()):
45
  processed_frames += 1
46
  print(f"Processing frame {processed_frames}")
47
  progress(processed_frames / total_frames, desc=f"Processing frame {processed_frames}/{total_frames}")
48
- out = remover.process(img, type='green')
49
  writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
50
 
51
  cap.release()
@@ -59,7 +62,7 @@ examples = [['./input.mp4']]
59
 
60
  iface = gr.Interface(
61
  fn=doo,
62
- inputs=["video", gr.components.Radio(['Normal', 'Fast'], label='Select mode', value='Normal', info='Normal is more accurate, but takes longer. | Fast has lower accuracy so the process will be faster.')],
63
  outputs="video",
64
  examples=examples,
65
  title=title,
 
12
  from transparent_background import Remover
13
 
14
  @spaces.GPU()
15
+ def doo(video, color, mode, progress=gr.Progress()):
16
+ color = color.lstrip('#')
17
+ rgb = tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
18
+ color = str(list(rgb))
19
  if mode == 'Fast':
20
  remover = Remover(mode='fast')
21
  else:
 
48
  processed_frames += 1
49
  print(f"Processing frame {processed_frames}")
50
  progress(processed_frames / total_frames, desc=f"Processing frame {processed_frames}/{total_frames}")
51
+ out = remover.process(img, type=color)
52
  writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
53
 
54
  cap.release()
 
62
 
63
  iface = gr.Interface(
64
  fn=doo,
65
+ inputs=["video", gr.ColorPicker(label="Background color", value="#00FF00"), gr.components.Radio(['Normal', 'Fast'], label='Select mode', value='Normal', info='Normal is more accurate, but takes longer. | Fast has lower accuracy so the process will be faster.')],
66
  outputs="video",
67
  examples=examples,
68
  title=title,