KingNish commited on
Commit
402afc5
1 Parent(s): c8cc221

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -112,11 +112,13 @@ def process(image, bg):
112
  pred_pil = transforms.ToPILImage()(pred)
113
  mask = pred_pil.resize(image_size)
114
 
115
- if bg.startswith("#"):
116
  color_rgb = tuple(int(bg[i:i+2], 16) for i in (1, 3, 5))
117
  background = Image.new("RGBA", image_size, color_rgb + (255,))
118
- else:
119
  background = bg.convert("RGBA").resize(image_size)
 
 
120
 
121
  # Composite the image onto the background using the mask
122
  image = Image.composite(image, background, mask)
@@ -126,10 +128,14 @@ def process(image, bg):
126
 
127
  with gr.Blocks(theme=gr.themes.Ocean()) as demo:
128
  with gr.Row():
129
- in_video = gr.Video(label="Input Video")
 
 
 
 
130
  stream_image = gr.Image(label="Streaming Output", visible=False)
131
  out_video = gr.Video(label="Final Output Video")
132
- submit_button = gr.Button("Change Background")
133
  with gr.Row():
134
  fps_slider = gr.Slider(
135
  minimum=0,
@@ -137,13 +143,14 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
137
  step=1,
138
  value=0,
139
  label="Output FPS (0 will inherit the original fps value)",
 
140
  )
141
- bg_type = gr.Radio(["Color", "Image", "Video"], label="Background Type", value="Color")
142
- color_picker = gr.ColorPicker(label="Background Color", value="#00FF00", visible=True)
143
- bg_image = gr.Image(label="Background Image", type="filepath", visible=False)
144
- bg_video = gr.Video(label="Background Video", visible=False)
145
  with gr.Column(visible=False) as video_handling_options:
146
- video_handling_radio = gr.Radio(["slow_down", "loop"], label="Video Handling", value="slow_down")
147
 
148
  def update_visibility(bg_type):
149
  if bg_type == "Color":
 
112
  pred_pil = transforms.ToPILImage()(pred)
113
  mask = pred_pil.resize(image_size)
114
 
115
+ if isinstance(bg, str) and bg.startswith("#"):
116
  color_rgb = tuple(int(bg[i:i+2], 16) for i in (1, 3, 5))
117
  background = Image.new("RGBA", image_size, color_rgb + (255,))
118
+ elif isinstance(bg, Image.Image):
119
  background = bg.convert("RGBA").resize(image_size)
120
+ else:
121
+ background = Image.open(bg).convert("RGBA").resize(image_size)
122
 
123
  # Composite the image onto the background using the mask
124
  image = Image.composite(image, background, mask)
 
128
 
129
  with gr.Blocks(theme=gr.themes.Ocean()) as demo:
130
  with gr.Row():
131
+ in_video = gr.Video(label="Input Video", interactive=True if isinstance(bg, str) and bg.startswith("#"):
132
+ color_rgb = tuple(int(bg[i:i+2], 16) for i in (1, 3, 5))
133
+ background = Image.new("RGBA", image_size, color_rgb + (255,))
134
+ elif isinstance(bg, Image.Image):
135
+ background = bg.convert("RGBA").resize(image_size))
136
  stream_image = gr.Image(label="Streaming Output", visible=False)
137
  out_video = gr.Video(label="Final Output Video")
138
+ submit_button = gr.Button("Change Background", interactive=True)
139
  with gr.Row():
140
  fps_slider = gr.Slider(
141
  minimum=0,
 
143
  step=1,
144
  value=0,
145
  label="Output FPS (0 will inherit the original fps value)",
146
+ interactive=True
147
  )
148
+ bg_type = gr.Radio(["Color", "Image", "Video"], label="Background Type", value="Color", interactive=True)
149
+ color_picker = gr.ColorPicker(label="Background Color", value="#00FF00", visible=True, interactive=True)
150
+ bg_image = gr.Image(label="Background Image", type="filepath", visible=False, interactive=True)
151
+ bg_video = gr.Video(label="Background Video", visible=False, interactive=True)
152
  with gr.Column(visible=False) as video_handling_options:
153
+ video_handling_radio = gr.Radio(["slow_down", "loop"], label="Video Handling", value="slow_down", interactive=True)
154
 
155
  def update_visibility(bg_type):
156
  if bg_type == "Color":