Janeka commited on
Commit
b2c440a
·
verified ·
1 Parent(s): d21f73b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -1,10 +1,10 @@
1
- import os
2
- from rembg import remove
3
- from io import BytesIO
4
  from fastapi import FastAPI, UploadFile, File, HTTPException
5
  from fastapi.responses import StreamingResponse
 
 
6
  import gradio as gr
7
 
 
8
  app = FastAPI()
9
 
10
  # Background removal function
@@ -22,6 +22,15 @@ def gradio_interface(input_image):
22
  output_bytes = remove_background(input_image)
23
  return output_bytes
24
 
 
 
 
 
 
 
 
 
 
25
  # API endpoint
26
  @app.post("/api/remove-bg")
27
  async def api_remove_bg(file: UploadFile = File(...)):
@@ -33,14 +42,5 @@ async def api_remove_bg(file: UploadFile = File(...)):
33
 
34
  return StreamingResponse(BytesIO(output_bytes), media_type="image/png")
35
 
36
- # Gradio app
37
- gr_app = gr.Interface(
38
- fn=gradio_interface,
39
- inputs=gr.Image(type="filepath", label="Input Image"),
40
- outputs=gr.Image(type="numpy", label="Output Image"),
41
- title="Background Remover",
42
- description="Upload an image to remove the background"
43
- )
44
-
45
- # Mount Gradio app
46
- app = gr.mount_gradio_app(app, gr_app, path="/")
 
 
 
 
1
  from fastapi import FastAPI, UploadFile, File, HTTPException
2
  from fastapi.responses import StreamingResponse
3
+ from rembg import remove
4
+ from io import BytesIO
5
  import gradio as gr
6
 
7
+ # Create FastAPI app
8
  app = FastAPI()
9
 
10
  # Background removal function
 
22
  output_bytes = remove_background(input_image)
23
  return output_bytes
24
 
25
+ # Create Gradio app
26
+ gradio_app = gr.Interface(
27
+ fn=gradio_interface,
28
+ inputs=gr.Image(type="filepath", label="Input Image"),
29
+ outputs=gr.Image(type="numpy", label="Output Image"),
30
+ title="Background Remover",
31
+ description="Upload an image to remove the background"
32
+ )
33
+
34
  # API endpoint
35
  @app.post("/api/remove-bg")
36
  async def api_remove_bg(file: UploadFile = File(...)):
 
42
 
43
  return StreamingResponse(BytesIO(output_bytes), media_type="image/png")
44
 
45
+ # Mount Gradio app to FastAPI
46
+ app = gr.mount_gradio_app(app, gradio_app, path="/")