Janeka commited on
Commit
8180ff8
·
verified ·
1 Parent(s): 053dcb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -32
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
- # Create background removal function
8
- def remove_background(image_bytes):
9
- try:
10
- return remove(image_bytes)
11
- except Exception as e:
12
- raise HTTPException(status_code=500, detail=str(e))
13
 
14
- # Create Gradio interface
15
- def gradio_interface(input_image):
16
- if input_image is None:
17
- return None
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
- # API endpoint
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)