|
from flask import Flask, request, send_file, redirect |
|
from werkzeug.utils import secure_filename |
|
from flask_cors import CORS |
|
|
|
import cv2 |
|
import os |
|
|
|
app = Flask(__name__) |
|
CORS(app) |
|
|
|
@app.route('/') |
|
def index(): |
|
return redirect('https://change-background-85e37.web.app/') |
|
|
|
@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)) |
|
w,h = image.shape[1],image.shape[0] |
|
image = cv2.resize(image,(int(w*.79),int(h*.79))) |
|
cv2.imwrite(secure_filename(file.filename).split('.')[0]+'.jpg',image) |
|
os.system("uname -a") |
|
|
|
outputName = secure_filename(file.filename).split('.')[0]+'.png' |
|
os.system('backgroundremover -i'+'{name}'.format(name= secure_filename(file.filename).split('.')[0]+'.jpg') + ' -m "u2net_human_seg" -o {name}'.format(name= outputName)) |
|
|
|
print(secure_filename(file.filename).split('.')) |
|
os.system("ls -l") |
|
return send_file(outputName,mimetype='image/png') |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
app.run(debug=True,host="0.0.0.0",port=5000) |