Spaces:
Runtime error
Runtime error
Commit
·
beeb85f
1
Parent(s):
e00f442
Add API Route
Browse files
main.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from rembg import remove
|
| 3 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def remove_background(input_image):
|
| 6 |
output_image = remove(input_image)
|
|
@@ -9,4 +12,13 @@ def remove_background(input_image):
|
|
| 9 |
inputs = gr.inputs.Image()
|
| 10 |
outputs = gr.outputs.Image(type='pil')
|
| 11 |
|
| 12 |
-
gr.Interface(fn=remove_background, inputs=inputs, outputs=outputs).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
|
|
|
| 12 |
inputs = gr.inputs.Image()
|
| 13 |
outputs = gr.outputs.Image(type='pil')
|
| 14 |
|
| 15 |
+
gr.Interface(fn=remove_background, inputs=inputs, outputs=outputs).launch()
|
| 16 |
+
|
| 17 |
+
@app.route("/api/remove-background", methods=["POST"])
|
| 18 |
+
def remove_background_api():
|
| 19 |
+
if request.method == "GET":
|
| 20 |
+
return "This API removes the background from an image. To use it, send a POST request to this URL with an image file in the 'input' field of the request body."
|
| 21 |
+
|
| 22 |
+
input_image = Image.open(request.files["input"])
|
| 23 |
+
output_image = remove_background(input_image)
|
| 24 |
+
return jsonify({"output": output_image})
|