Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,8 @@
|
|
| 1 |
-
from
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|