代码拉取完成,页面将自动刷新
# 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。