File size: 1,234 Bytes
7975728
fa1eec9
 
 
 
ad8d51e
fa1eec9
 
 
 
 
 
7975728
fa1eec9
 
 
 
 
 
 
9fc9fdc
eee9704
3f4ba22
68ff489
 
3f4ba22
 
fa1eec9
ad8d51e
fa1eec9
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from flask import Flask, request, send_file, redirect
from werkzeug.utils import secure_filename
from flask_cors import CORS
from rembg import remove
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]
    os.system("uname -a")
    #output = remove(image)  # remove background
    outputName = secure_filename(file.filename).split('.')[0]+'.png'
    os.system('backgroundremover -i'+'{name}'.format(name= secure_filename(file.filename)) + ' -m "u2net_human_seg" -o {name}'.format(name= outputName))
    #output = cv2.resize(output,(int(w*.79),int(h*.79)))
    #cv2.imwrite(secure_filename(file.filename).split('.')[0]+'.png',output)
    print(secure_filename(file.filename).split('.'))
    os.system("ls -l")
    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)