Spaces:
Running
on
L40S
Running
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -33,26 +33,26 @@ def remove_background(input_url):
|
|
33 |
# Download the image from the URL
|
34 |
image_path = os.path.join(temp_dir, 'input_image.png')
|
35 |
try:
|
36 |
-
image = Image.open(input_url)
|
37 |
image.save(image_path)
|
38 |
except Exception as e:
|
39 |
shutil.rmtree(temp_dir)
|
40 |
return f"Error downloading or saving the image: {str(e)}"
|
41 |
|
42 |
-
"""
|
43 |
# Run background removal
|
44 |
try:
|
45 |
removed_bg_path = os.path.join(temp_dir, 'output_image_rmbg.png')
|
46 |
img = Image.open(image_path)
|
47 |
result = remove(img)
|
48 |
result.save(removed_bg_path)
|
|
|
|
|
|
|
49 |
except Exception as e:
|
50 |
shutil.rmtree(temp_dir)
|
51 |
return f"Error removing background: {str(e)}"
|
52 |
|
53 |
return removed_bg_path, temp_dir
|
54 |
-
"""
|
55 |
-
return image_path, temp_dir
|
56 |
|
57 |
def run_inference(temp_dir):
|
58 |
# Define the inference configuration
|
|
|
33 |
# Download the image from the URL
|
34 |
image_path = os.path.join(temp_dir, 'input_image.png')
|
35 |
try:
|
36 |
+
image = Image.open(input_url)
|
37 |
image.save(image_path)
|
38 |
except Exception as e:
|
39 |
shutil.rmtree(temp_dir)
|
40 |
return f"Error downloading or saving the image: {str(e)}"
|
41 |
|
|
|
42 |
# Run background removal
|
43 |
try:
|
44 |
removed_bg_path = os.path.join(temp_dir, 'output_image_rmbg.png')
|
45 |
img = Image.open(image_path)
|
46 |
result = remove(img)
|
47 |
result.save(removed_bg_path)
|
48 |
+
|
49 |
+
# Remove the input image to keep the temp directory clean
|
50 |
+
os.remove(image_path)
|
51 |
except Exception as e:
|
52 |
shutil.rmtree(temp_dir)
|
53 |
return f"Error removing background: {str(e)}"
|
54 |
|
55 |
return removed_bg_path, temp_dir
|
|
|
|
|
56 |
|
57 |
def run_inference(temp_dir):
|
58 |
# Define the inference configuration
|