1 Star 1 Fork 1

不戒/Landscape-Heath-Score

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.py 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
JiehangXie 提交于 2021-08-03 12:30 . 新增内容
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiejiehang/Landscape-Heath-Score.git
git@gitee.com:xiejiehang/Landscape-Heath-Score.git
xiejiehang
Landscape-Heath-Score
Landscape-Heath-Score
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385