dhanushreddy29 commited on
Commit
54c613b
·
1 Parent(s): f0b4848

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -23
main.py CHANGED
@@ -1,33 +1,26 @@
1
  import gradio as gr
2
  from rembg import remove
3
  from PIL import Image
4
- from flask import Flask, request, jsonify
5
 
6
- app = Flask(__name__)
7
 
8
  def remove_background(input_image):
9
  output_image = remove(input_image)
10
  return output_image
11
 
12
- inputs = gr.inputs.Image()
13
- outputs = gr.outputs.Image(type='pil')
14
-
15
- interface = gr.Interface(fn=remove_background, inputs=inputs, outputs=outputs, title="Remove Background", description="This App removes the background from an image.", api="flask")
16
- interface.launch()
17
 
18
- @app.route("/api/remove-background", methods=["POST"])
19
- def remove_background_api():
20
- input_image = Image.open(request.files["input"])
21
- output_image = remove_background(input_image)
22
- return jsonify({"output": output_image})
23
-
24
- # Custom HTML block with API instructions
25
- interface.interface_html = """
26
- <div style="padding: 1rem; margin: 1rem 0; border: 1px solid black;">
27
- <h3>API Instructions:</h3>
28
- <ol>
29
- <li>Send a POST request to the '/api/remove-background' endpoint with an image file in the 'input' field of the request body.</li>
30
- <li>The output image will be returned as a byte string in the 'output' field of the JSON response.</li>
31
- </ol>
32
- </div>
33
- """
 
1
  import gradio as gr
2
  from rembg import remove
3
  from PIL import Image
 
4
 
 
5
 
6
  def remove_background(input_image):
7
  output_image = remove(input_image)
8
  return output_image
9
 
 
 
 
 
 
10
 
11
+ inputs = gr.inputs.Image()
12
+ outputs = gr.outputs.Image(type="pil")
13
+ interface = gr.Interface(
14
+ fn=remove_background,
15
+ inputs=inputs,
16
+ outputs=outputs,
17
+ title="Remove Background",
18
+ description="This App removes the background from an image",
19
+ examples=[
20
+ "examples/input/1.jpeg",
21
+ "examples/input/2.jpeg",
22
+ "examples/input/3.jpeg",
23
+ ],
24
+ cache_examples=True,
25
+ )
26
+ interface.launch(enable_queue=True)