Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何写成一个rest api接口供前端调用? #9

Open
yeyuliang2015 opened this issue Dec 18, 2018 · 2 comments
Open

如何写成一个rest api接口供前端调用? #9

yeyuliang2015 opened this issue Dec 18, 2018 · 2 comments

Comments

@yeyuliang2015
Copy link

No description provided.

@chenyangjun45
Copy link

我觉得可以加个Django可以实现

@Shkin1
Copy link

Shkin1 commented Sep 1, 2020

问答的目前只需要一个接口即可, 并不需要上Django框架
建议直接使用flask即可
from flask import Flask, jsonify, request
from flask_cors import *

app = Flask(name)
@app.route("/qa/getAnswer", methods=['GET'])
@cross_origin()
def runModel():
question = str(request.args.get('info'))
print("question: "+question)
answer = handler.chat_main(question)
data = str("南帝医生:"+answer)
print(data).decode('string-escape')
return jsonify(text=data)

if name == 'main':
# 训练模型
print("医药学知识库训练模型ing ...")
handler = ChatBotGraph()
print("完成模型训练 ...")
app.run(host='127.0.0.1', port=8002)

测试接口:
url: 127.0.0.1:8002/qa/getAnswer?info=感冒高血压关系并发吃啥
请求方式: GET
返回:
{
"text": "南帝医生:高血压的症状包括:高原适应不全症;胰岛素抵抗与代谢综合征;酒精中毒性神经疾病;脑出血;血管性帕金森综合征;小儿阻塞性睡眠呼吸暂停;蓝鼓膜与胆固醇肉芽肿;高原性心脏病;肾功能不全;慢性肾盂肾炎;隐匿型肾炎;支气管炎;Ⅳ型肾小管性酸中毒;妊娠合并红细胞增多症;小儿指甲-髌骨综合征;小儿慢性肾小球肾炎;小儿麻痹症;安卡性肾炎;口腔疾病;小儿原发性膀胱输尿管反流\n高血压宜食的食物包括有:鸡肉;鸡蛋;芝麻;南瓜子仁;鹌鹑蛋;松子仁\n推荐食谱包括有:香脆芹菜叶;香椿芽粥;芹菜粥;醋熘土豆丝;素熘菜花;姜丝萝卜汤;赤小豆粥;葱蒜粥;凉拌香椿;葛根粉粥;胡萝卜粥;清盐菜花;绿豆薏米饭;薏米莲子粥;灵芝羹"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants