1 Star 1 Fork 0

松糕不能吃/flask_vue_ML

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.py 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
kuhung 提交于 2020-04-11 18:01 . update it
from flask import Flask, jsonify, request
# from flask_pymongo import PyMongo
from bson.objectid import ObjectId
from flask_cors import CORS
from flair.models import TextClassifier
from flair.data import Sentence
from flask import session
import os
model_path = '/root/flask_vue_ML'
expose = Flask(__name__)
expose.secret_key = "super_secret_key"
# expose.config['MONGO_DBNAME'] = 'exposeModel'
# expose.config['MONGO_URI'] = 'mongodb://localhost:27017/exposeModel'
# mongo = PyMongo(expose)
CORS(expose)
classifier = TextClassifier.load_from_file(os.path.join(model_path,'models/best-model.pt'))
@expose.route('/', methods=['GET'])
def index():
return jsonify("welcome to Arafa API")
@expose.route('/api/tasks', methods=['GET'])
def get_result():
result = []
try:
data_result = session['my_result']
result.append ({'title': data_result['title'], 'tag': data_result['tag'] })
except:
result.append ({'title': 'The txt you input', 'tag': 'spam or harm' })
return jsonify(result)
@expose.route('/api/task', methods=['POST','GET'])
def input_predict_text():
title = request.get_json()['title']
# TODO: title type check
sentence = Sentence(title)
classifier.predict(sentence)
text = sentence.to_plain_string()
label = sentence.labels[0]
result = {'title' : text, 'tag' : label.value}
session['my_result'] = result
return jsonify(result)
if __name__ == '__main__':
# expose.run(debug=True)
expose.run(host='0.0.0.0')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yummycake/flask_vue_ML.git
git@gitee.com:yummycake/flask_vue_ML.git
yummycake
flask_vue_ML
flask_vue_ML
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385