Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from rembg import remove
|
| 3 |
-
from fastapi import FastAPI, UploadFile, File, HTTPException
|
| 4 |
-
from fastapi.responses import Response
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
return remove(image_bytes)
|
| 11 |
-
except Exception as e:
|
| 12 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return remove_background(input_image)
|
| 19 |
-
|
| 20 |
-
# Create FastAPI app
|
| 21 |
-
app = FastAPI()
|
| 22 |
-
|
| 23 |
-
# Create and mount Gradio app
|
| 24 |
-
gradio_app = gr.Interface(
|
| 25 |
-
fn=gradio_interface,
|
| 26 |
-
inputs=gr.Image(type="filepath"),
|
| 27 |
-
outputs=gr.Image(type="filepath"),
|
| 28 |
title="Background Remover",
|
| 29 |
description="Upload an image to remove the background",
|
| 30 |
allow_flagging="never"
|
| 31 |
)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
@app.post("/api/remove-bg")
|
| 35 |
-
async def api_remove_bg(file: UploadFile = File(...)):
|
| 36 |
-
image_bytes = await file.read()
|
| 37 |
-
output_bytes = remove_background(image_bytes)
|
| 38 |
-
return Response(content=output_bytes, media_type="image/png")
|
| 39 |
-
|
| 40 |
-
# Mount Gradio app
|
| 41 |
-
app = gr.mount_gradio_app(app, gradio_app, path="/")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from rembg import remove
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
def remove_background(input_image):
|
| 5 |
+
output = remove(input_image)
|
| 6 |
+
return output
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
interface = gr.Interface(
|
| 9 |
+
fn=remove_background,
|
| 10 |
+
inputs=gr.Image(type="filepath", label="Input Image"),
|
| 11 |
+
outputs=gr.Image(type="filepath", label="Output Image"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
title="Background Remover",
|
| 13 |
description="Upload an image to remove the background",
|
| 14 |
allow_flagging="never"
|
| 15 |
)
|
| 16 |
|
| 17 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|