加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
http_server.py 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
m_engmeng 提交于 2023-11-07 08:51 . http通信服务端
# server.py
from flask import Flask, request, jsonify
from loguru import logger
import reque_pb2
import math_problems_new
import poems_problems
import English_problems
import AI_problems
import image_text
app = Flask(__name__)
@app.route('/get_questions', methods=['GET', 'POST'])
def get_questions():
try:
data = request.get_json()
grade = data['keyword']['grade']
subject = data['keyword']['subject']
topic = data['keyword']['topic']
difficulty = data['keyword']['difficulty']
quantity = data['quantity']
difficulty_list = ['easy', 'midum', 'hard']
Grades = ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级']
if subject == '数学' and topic in [0, 1, 2, 3] and difficulty in difficulty_list and grade in Grades:
question = math_problems_new.get_request(grade, int(topic), quantity, difficulty)
elif subject == '语文' and topic in [0, 1, 2] and difficulty in difficulty_list and grade in Grades:
question = poems_problems.get_request(grade, int(topic), quantity, difficulty)
elif subject == '英语' and topic in [0, 1, 2] and difficulty in difficulty_list and grade in Grades[2:]:
question = English_problems.get_request(grade, topic, quantity, difficulty)
elif subject in ['英语', '语文'] and topic == 3 and difficulty == 'hard':
question = AI_problems.get_request(subject, grade, topic, quantity, difficulty)
elif subject == 'magic' and topic in [0, 1, 2]:
question = image_text.get_request(topic, quantity)
else:
question = [{'question_text': "问题请求错误", 'answer': "暂无答案"}]
#
# result = {
# 'questions': question
# }
result = question
return jsonify(result)
except Exception as e:
logger.error(str(e))
return jsonify({'error': 'An error occurred'}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9000)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化