Mystyc commited on
Commit
adf71ac
·
verified ·
1 Parent(s): 475e76d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -24
app.py CHANGED
@@ -1,24 +1,8 @@
1
- from fastapi import FastAPI, UploadFile, File, Response, HTTPException
2
- from rembg import remove
3
- from PIL import Image
4
- import io
5
-
6
- app = FastAPI(title="RemoveBG (rembg) – FastAPI")
7
-
8
- @app.get("/")
9
- def root():
10
- return {"ok": True, "message": "Use POST /removebg with multipart field 'file'"}
11
-
12
- @app.post("/removebg")
13
- async def removebg(file: UploadFile = File(...)):
14
- try:
15
- # baca bytes gambar
16
- b = await file.read()
17
- # pastikan bisa dibuka PIL (validasi ringan)
18
- Image.open(io.BytesIO(b))
19
-
20
- # rembg menerima bytes atau PIL image
21
- out_bytes = remove(b) # hasil PNG RGBA
22
- return Response(content=out_bytes, media_type="image/png")
23
- except Exception as e:
24
- raise HTTPException(status_code=400, detail=f"Failed to process: {e}")
 
1
+ from gradio_client import Client, handle_file
2
+
3
+ client = Client("not-lain/background-removal")
4
+ result = client.predict(
5
+ f=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
6
+ api_name="/png"
7
+ )
8
+ print(result)