Janeka commited on
Commit
ba31357
·
verified ·
1 Parent(s): 22beb92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -3,12 +3,26 @@ import torch
3
  from rembg import remove
4
  from PIL import Image
5
  import io
 
6
 
7
  def remove_bg(image):
8
  output_image = remove(image)
9
  return output_image
10
 
 
11
  demo = gr.Interface(fn=remove_bg, inputs=gr.Image(type="pil"), outputs="image")
12
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  if __name__ == "__main__":
14
- demo.launch()
 
3
  from rembg import remove
4
  from PIL import Image
5
  import io
6
+ from fastapi.middleware.cors import CORSMiddleware
7
 
8
  def remove_bg(image):
9
  output_image = remove(image)
10
  return output_image
11
 
12
+ # Gradio interface
13
  demo = gr.Interface(fn=remove_bg, inputs=gr.Image(type="pil"), outputs="image")
14
 
15
+ # FastAPI app for adding CORS middleware
16
+ app = demo.launch(prevent_thread_lock=True)
17
+
18
+ # Adding CORS to allow requests from anywhere
19
+ app.add_middleware(
20
+ CORSMiddleware,
21
+ allow_origins=["*"], # Allows requests from any origin
22
+ allow_credentials=True,
23
+ allow_methods=["*"],
24
+ allow_headers=["*"],
25
+ )
26
+
27
  if __name__ == "__main__":
28
+ demo.launch()