Spaces:
Running on Zero
Running on Zero
Download app.py from fedorajuandy/remove-background: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/fedorajuandy/remove-background/resolve/main/app.py
- Command line
-
hf download hf://spaces/fedorajuandy/remove-background/app.py
-
curl -L -o app.py https://huggingface.co/spaces/fedorajuandy/remove-background/resolve/main/app.py
1.36 kB
| """Hugging Face Spaces entry point for BiRefNet background removal.""" | |
| # ZeroGPU requires this import and decorator. The fallback keeps local and | |
| # ordinary CPU Spaces usable without the Hugging Face-only ``spaces`` package. | |
| try: | |
| import spaces | |
| except ImportError: | |
| class _LocalSpaces: | |
| def GPU(**_kwargs): | |
| return lambda function: function | |
| spaces = _LocalSpaces() | |
| import gradio as gr | |
| from remove_background import remove_background | |
| def process(image): | |
| """Adapt the reusable image function to Gradio's callback interface.""" | |
| return remove_background(image) | |
| with gr.Blocks(title="BiRefNet Background Remover") as demo: | |
| gr.Markdown( | |
| """ | |
| # BiRefNet Background Remover | |
| Upload an image to create a PNG with a transparent background. | |
| The first request may take longer while the BiRefNet model is downloaded. | |
| """ | |
| ) | |
| with gr.Row(): | |
| source = gr.Image(label="Image", type="pil", sources=["upload"]) | |
| result = gr.Image(label="Transparent PNG", type="pil", format="png") | |
| run_button = gr.Button("Remove background", variant="primary") | |
| run_button.click(process, inputs=source, outputs=result, api_name="remove_background") | |
| demo.queue(default_concurrency_limit=1) | |
| if __name__ == "__main__": | |
| demo.launch() | |