Spaces:
Paused
Paused
VINU NAYAK commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,13 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from fastapi.responses import StreamingResponse
|
| 3 |
from rembg import remove
|
| 4 |
-
from PIL import Image
|
| 5 |
import io
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
@app.post("/remove-bg")
|
| 10 |
async def remove_bg(file: UploadFile = File(...)):
|
| 11 |
-
|
| 12 |
-
input_image = Image.open(io.BytesIO(input_bytes)).convert("RGBA")
|
| 13 |
-
|
| 14 |
-
# Remove background
|
| 15 |
output_image = remove(input_image)
|
| 16 |
-
|
| 17 |
-
# Convert output to byte stream
|
| 18 |
-
img_byte_arr = io.BytesIO()
|
| 19 |
-
output_image.save(img_byte_arr, format='PNG')
|
| 20 |
-
img_byte_arr.seek(0)
|
| 21 |
-
|
| 22 |
-
return StreamingResponse(img_byte_arr, media_type="image/png")
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
from fastapi import FastAPI, UploadFile, File
|
| 3 |
from fastapi.responses import StreamingResponse
|
| 4 |
from rembg import remove
|
|
|
|
| 5 |
import io
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
@app.post("/remove-bg")
|
| 10 |
async def remove_bg(file: UploadFile = File(...)):
|
| 11 |
+
input_image = await file.read()
|
|
|
|
|
|
|
|
|
|
| 12 |
output_image = remove(input_image)
|
| 13 |
+
return StreamingResponse(io.BytesIO(output_image), media_type="image/png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|