Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,20 @@
|
|
| 1 |
-
import
|
| 2 |
-
import sys
|
| 3 |
-
import logging
|
| 4 |
from rembg import remove
|
| 5 |
-
from PIL import Image
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
image = Image.open(image_path)
|
| 25 |
-
|
| 26 |
-
# Remove the background
|
| 27 |
-
image_no_bg = remove(image)
|
| 28 |
-
|
| 29 |
-
# Save the output image with the prefix 'bg-rm_'
|
| 30 |
-
output_filename = 'bg-rm_' + filename
|
| 31 |
-
output_path = os.path.join(output_folder, output_filename)
|
| 32 |
-
image_no_bg.save(output_path)
|
| 33 |
-
|
| 34 |
-
# Log success
|
| 35 |
-
logging.info(f'Processed: {filename}')
|
| 36 |
-
|
| 37 |
-
except Exception as e:
|
| 38 |
-
# Log error
|
| 39 |
-
logging.error(f'Error processing {filename}: {e}')
|
| 40 |
-
|
| 41 |
-
def main():
|
| 42 |
-
# Check command-line arguments
|
| 43 |
-
if len(sys.argv) != 3:
|
| 44 |
-
print(f'Usage: {sys.argv[0]} input_folder output_folder')
|
| 45 |
-
sys.exit(1)
|
| 46 |
-
|
| 47 |
-
# Get input and output folders from command-line arguments
|
| 48 |
-
input_folder = sys.argv[1]
|
| 49 |
-
output_folder = sys.argv[2]
|
| 50 |
-
|
| 51 |
-
# Process the images in the input folder
|
| 52 |
-
process_folder(input_folder, output_folder)
|
| 53 |
-
|
| 54 |
-
if __name__ == '__main__':
|
| 55 |
-
main()
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from rembg import remove
|
|
|
|
| 3 |
|
| 4 |
+
title = "Vanish Background"
|
| 5 |
+
description = "Remove background for any image. To use it, simply upload your image(s) and wait. Read more at the link below of official documentation."
|
| 6 |
+
article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
|
| 7 |
+
|
| 8 |
+
def segment(images):
|
| 9 |
+
# Process each image in the list and remove the background
|
| 10 |
+
return [remove(image) for image in images]
|
| 11 |
+
|
| 12 |
+
demo = gr.Interface(
|
| 13 |
+
fn=segment,
|
| 14 |
+
inputs=gr.inputs.Image(type="file", label="Upload Image(s)", multiple=True),
|
| 15 |
+
outputs=gr.outputs.Image(type="file", label="Image(s) with Background Removed"),
|
| 16 |
+
title=title,
|
| 17 |
+
description=description,
|
| 18 |
+
article=article
|
| 19 |
+
)
|
| 20 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|