muhammadzain's picture
backend 0
ecfdc6c
from flask import Flask, request, send_file
from werkzeug.utils import secure_filename
from flask_cors import CORS
from rembg import remove
import cv2
app = Flask(__name__)
CORS(app)
@app.route('/')
def index():
return "Please use frontend"
@app.route('/data',methods = ['POST'])
def inference():
file = request.files['file']
file.save(secure_filename(file.filename))
file_name = file.filename
image = cv2.imread(secure_filename(file_name))
output = remove(image) # remove background
cv2.imwrite(secure_filename(file.filename).split('.')[0]+'.png',output)
print(secure_filename(file.filename).split('.'))
return send_file(secure_filename(file.filename).split('.')[0]+'.png',mimetype='image/png')
if __name__ == "__main__":
app.run(debug=True,host="0.0.0.0",port=5000)