fffiloni commited on
Commit
a98ca14
·
verified ·
1 Parent(s): 5af5758

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -36,7 +36,7 @@ images_examples = [
36
  if os.path.isfile(os.path.join(examples_folder, file))
37
  ]
38
 
39
- def remove_background(input_url, remove_bg):
40
  # Create a temporary folder for downloaded and processed images
41
  temp_dir = tempfile.mkdtemp()
42
 
@@ -55,11 +55,10 @@ def remove_background(input_url, remove_bg):
55
  unique_id = str(uuid.uuid4())
56
  removed_bg_path = os.path.join(temp_dir, f'output_image_rmbg_{unique_id}.png')
57
  img = Image.open(image_path)
58
- if remove_bg:
59
- result = remove(img)
60
- result.save(removed_bg_path)
61
- else:
62
- img.save(removed_bg_path)
63
 
64
  # Remove the input image to keep the temp directory clean
65
  os.remove(image_path)
@@ -103,9 +102,9 @@ def run_inference(temp_dir, removed_bg_path):
103
  except subprocess.CalledProcessError as e:
104
  return f"Error during inference: {str(e)}"
105
 
106
- def process_image(input_url, remove_bg):
107
  # Remove background
108
- result = remove_background(input_url, remove_bg)
109
 
110
  if isinstance(result, str) and result.startswith("Error"):
111
  raise gr.Error(f"{result}") # Return the error message if something went wrong
@@ -154,11 +153,6 @@ def gradio_interface():
154
  type="filepath",
155
  height=240
156
  )
157
-
158
- remove_bg = gr.Checkbox(
159
- label="Need to remove BG ?",
160
- value=False
161
- )
162
 
163
  submit_button = gr.Button("Process")
164
  gr.Examples(
@@ -169,7 +163,7 @@ def gradio_interface():
169
 
170
  output_video= gr.Video(label="Output Video", scale=4)
171
 
172
- submit_button.click(process_image, inputs=[input_image, remove_bg], outputs=[output_video])
173
 
174
  return app
175
 
 
36
  if os.path.isfile(os.path.join(examples_folder, file))
37
  ]
38
 
39
+ def remove_background(input_url):
40
  # Create a temporary folder for downloaded and processed images
41
  temp_dir = tempfile.mkdtemp()
42
 
 
55
  unique_id = str(uuid.uuid4())
56
  removed_bg_path = os.path.join(temp_dir, f'output_image_rmbg_{unique_id}.png')
57
  img = Image.open(image_path)
58
+
59
+ result = remove(img)
60
+ result.save(removed_bg_path)
61
+
 
62
 
63
  # Remove the input image to keep the temp directory clean
64
  os.remove(image_path)
 
102
  except subprocess.CalledProcessError as e:
103
  return f"Error during inference: {str(e)}"
104
 
105
+ def process_image(input_url):
106
  # Remove background
107
+ result = remove_background(input_url)
108
 
109
  if isinstance(result, str) and result.startswith("Error"):
110
  raise gr.Error(f"{result}") # Return the error message if something went wrong
 
153
  type="filepath",
154
  height=240
155
  )
 
 
 
 
 
156
 
157
  submit_button = gr.Button("Process")
158
  gr.Examples(
 
163
 
164
  output_video= gr.Video(label="Output Video", scale=4)
165
 
166
+ submit_button.click(process_image, inputs=[input_image], outputs=[output_video])
167
 
168
  return app
169