Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
# app.py
|
| 2 |
-
#
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
from rembg import remove
|
|
|
|
| 6 |
|
| 7 |
-
# The core function
|
| 8 |
def process_image(input_image):
|
| 9 |
if input_image is None:
|
| 10 |
raise gr.Error("No image provided.")
|
|
@@ -12,20 +13,20 @@ def process_image(input_image):
|
|
| 12 |
# Use the default rembg model for stability.
|
| 13 |
return remove(input_image)
|
| 14 |
except Exception as e:
|
|
|
|
| 15 |
raise gr.Error(f"Failed to process image: {e}")
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
# The `api_name="predict"` explicitly creates an endpoint at `/run/predict`.
|
| 19 |
demo = gr.Interface(
|
| 20 |
fn=process_image,
|
| 21 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
| 22 |
outputs=gr.Image(type="pil", label="Background Removed"),
|
| 23 |
title="Background Remover API",
|
| 24 |
-
description="A simple API for removing image backgrounds.",
|
| 25 |
allow_flagging="never",
|
|
|
|
| 26 |
api_name="predict"
|
| 27 |
)
|
| 28 |
|
| 29 |
-
# Launch the app.
|
| 30 |
if __name__ == "__main__":
|
| 31 |
demo.launch()
|
|
|
|
| 1 |
# app.py
|
| 2 |
+
# FINAL SIMPLIFIED VERSION - No secret key, to match working examples.
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
from rembg import remove
|
| 6 |
+
import traceback
|
| 7 |
|
| 8 |
+
# The core function now only takes one argument.
|
| 9 |
def process_image(input_image):
|
| 10 |
if input_image is None:
|
| 11 |
raise gr.Error("No image provided.")
|
|
|
|
| 13 |
# Use the default rembg model for stability.
|
| 14 |
return remove(input_image)
|
| 15 |
except Exception as e:
|
| 16 |
+
print(traceback.format_exc())
|
| 17 |
raise gr.Error(f"Failed to process image: {e}")
|
| 18 |
|
| 19 |
+
# The Interface now only has one input component.
|
|
|
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=process_image,
|
| 22 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
| 23 |
outputs=gr.Image(type="pil", label="Background Removed"),
|
| 24 |
title="Background Remover API",
|
| 25 |
+
description="A simple public API for removing image backgrounds.",
|
| 26 |
allow_flagging="never",
|
| 27 |
+
# This explicitly creates the endpoint at /run/predict
|
| 28 |
api_name="predict"
|
| 29 |
)
|
| 30 |
|
|
|
|
| 31 |
if __name__ == "__main__":
|
| 32 |
demo.launch()
|