Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,15 +6,7 @@ import numpy as np
|
|
| 6 |
|
| 7 |
def remove_bg(image):
|
| 8 |
try:
|
| 9 |
-
|
| 10 |
-
if isinstance(image, str): # file path
|
| 11 |
-
img = Image.open(image)
|
| 12 |
-
elif isinstance(image, np.ndarray): # numpy array from Gradio
|
| 13 |
-
img = Image.fromarray(image)
|
| 14 |
-
else:
|
| 15 |
-
raise ValueError("Unsupported input type")
|
| 16 |
-
|
| 17 |
-
# Process with rembg
|
| 18 |
img_byte_arr = io.BytesIO()
|
| 19 |
img.save(img_byte_arr, format='PNG')
|
| 20 |
output_bytes = remove(img_byte_arr.getvalue())
|
|
@@ -22,16 +14,16 @@ def remove_bg(image):
|
|
| 22 |
except Exception as e:
|
| 23 |
raise gr.Error(f"Error processing image: {str(e)}")
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
# Launch the app (API is automatically enabled in newer Gradio versions)
|
| 36 |
if __name__ == "__main__":
|
| 37 |
-
|
|
|
|
| 6 |
|
| 7 |
def remove_bg(image):
|
| 8 |
try:
|
| 9 |
+
img = Image.open(image) if isinstance(image, str) else Image.fromarray(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
img_byte_arr = io.BytesIO()
|
| 11 |
img.save(img_byte_arr, format='PNG')
|
| 12 |
output_bytes = remove(img_byte_arr.getvalue())
|
|
|
|
| 14 |
except Exception as e:
|
| 15 |
raise gr.Error(f"Error processing image: {str(e)}")
|
| 16 |
|
| 17 |
+
with gr.Blocks() as demo:
|
| 18 |
+
gr.Markdown("# Background Remover")
|
| 19 |
+
with gr.Row():
|
| 20 |
+
with gr.Column():
|
| 21 |
+
input_image = gr.Image(type="filepath", label="Input Image")
|
| 22 |
+
submit_btn = gr.Button("Remove Background")
|
| 23 |
+
with gr.Column():
|
| 24 |
+
output_image = gr.Image(label="Output Image", type="pil")
|
| 25 |
+
|
| 26 |
+
submit_btn.click(remove_bg, inputs=input_image, outputs=output_image)
|
| 27 |
|
|
|
|
| 28 |
if __name__ == "__main__":
|
| 29 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|