File size: 809 Bytes
ed52a1b beeb85f ed52a1b beeb85f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from rembg import remove
from PIL import Image
from flask import Flask, request, jsonify
app = Flask(__name__)
def remove_background(input_image):
output_image = remove(input_image)
return output_image
inputs = gr.inputs.Image()
outputs = gr.outputs.Image(type='pil')
gr.Interface(fn=remove_background, inputs=inputs, outputs=outputs).launch()
@app.route("/api/remove-background", methods=["POST"])
def remove_background_api():
if request.method == "GET":
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."
input_image = Image.open(request.files["input"])
output_image = remove_background(input_image)
return jsonify({"output": output_image}) |