代码拉取完成,页面将自动刷新
from flask import Flask,request,jsonify,render_template
from infer_api import seg_api
from base64 import b64encode
from flask_cors import *
from io import BytesIO
from gevent import pywsgi
from network import check_ipv6
app = Flask(__name__,template_folder="./dist",
static_folder="./dist/assets")
CORS(app, supports_credentials=True)
@app.route('/', defaults = {'path': ''}, methods=['GET'])
@app.route('/<path:path>')
def catch_all(path):
return render_template("index.html")
@app.route('/api/v1/<datatype>',methods=['POST'])
def api_v1(datatype):
if datatype == 'file':
data = request.files.get('file')
buffered = BytesIO()
data.save(buffered)
image_base64 = b64encode(buffered.getvalue()).decode('utf-8')
elif datatype == 'json':
data = request.get_json()
image_base64 = data['image']
else:
return jsonify(msg="error")
result = seg_api(image_base64)
image_seg_result,image_base64_result,score,GLR = result[0],result[1],result[2],result[3]
return jsonify(proportion=image_seg_result,image=image_base64_result,score=score,gvr=GLR)
if __name__ == '__main__':
ipv6_support = check_ipv6()
if ipv6_support:
server = pywsgi.WSGIServer(('::', 5000), app) #ipv6
else:
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app) #ipv4
print('Run successfully!Please use your browser to access the following ip address:')
print('--- http://localhost:5000/ ')
server.serve_forever()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。