KurtDu commited on
Commit
1dee20a
·
verified ·
1 Parent(s): 7416ced

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -42,8 +42,15 @@ def load_test_data(task):
42
  with open('/app/test_text.txt', 'r') as file:
43
  content = file.read()
44
  print(content)
45
- with open(os.path.join(DATA_DIR, f"{task}.json"), "r", encoding='utf-8') as f:
46
- test_data = json.load(f)
 
 
 
 
 
 
 
47
 
48
  # 更新音频路径,将它们指向 Flask 静态文件夹
49
  for item in test_data:
@@ -79,6 +86,8 @@ def start_test():
79
 
80
  # Load the test data
81
  test_data = load_test_data(task)
 
 
82
 
83
  # Shuffle test data for the user
84
  random.shuffle(test_data)
@@ -95,6 +104,9 @@ def start_test():
95
 
96
  task_description = test_data[0].get('task_description', '')
97
 
 
 
 
98
  return jsonify({"message": "Test started", "total_tests": len(test_data), "task_description": task_description})
99
 
100
 
@@ -102,8 +114,12 @@ def start_test():
102
  @app.route('/next_test', methods=['GET'])
103
  def next_test():
104
  """Serve the next test item"""
 
 
 
105
  if 'current_index' not in session or 'test_data' not in session:
106
- return jsonify({"message": "No active test found"}), 400
 
107
 
108
  current_index = session['current_index']
109
  test_data = session['test_data']
@@ -115,6 +131,9 @@ def next_test():
115
  # 使用 EloRank 的 sample_next_match 来选择两款模型
116
  selected_models = elo_rank_system.sample_next_match()
117
 
 
 
 
118
  # Serve test data with the two selected models
119
  current_test = test_data[current_index]
120
  session['selected_models'] = selected_models
 
42
  with open('/app/test_text.txt', 'r') as file:
43
  content = file.read()
44
  print(content)
45
+ # with open(os.path.join(DATA_DIR, f"{task}.json"), "r", encoding='utf-8') as f:
46
+ # test_data = json.load(f)
47
+
48
+ try:
49
+ with open(os.path.join(DATA_DIR, f"{task}.json"), "r", encoding='utf-8') as f:
50
+ test_data = json.load(f)
51
+ except FileNotFoundError:
52
+ return jsonify({"message": "Test data file not found"}), 400
53
+
54
 
55
  # 更新音频路径,将它们指向 Flask 静态文件夹
56
  for item in test_data:
 
86
 
87
  # Load the test data
88
  test_data = load_test_data(task)
89
+ if not test_data:
90
+ return jsonify({"message": "No test data available"}), 400
91
 
92
  # Shuffle test data for the user
93
  random.shuffle(test_data)
 
104
 
105
  task_description = test_data[0].get('task_description', '')
106
 
107
+ print(session)
108
+
109
+
110
  return jsonify({"message": "Test started", "total_tests": len(test_data), "task_description": task_description})
111
 
112
 
 
114
  @app.route('/next_test', methods=['GET'])
115
  def next_test():
116
  """Serve the next test item"""
117
+ # if 'current_index' not in session or 'test_data' not in session:
118
+ # return jsonify({"message": "No active test found"}), 400
119
+
120
  if 'current_index' not in session or 'test_data' not in session:
121
+ return jsonify({"message": "Session data missing", "session": session}), 400
122
+
123
 
124
  current_index = session['current_index']
125
  test_data = session['test_data']
 
131
  # 使用 EloRank 的 sample_next_match 来选择两款模型
132
  selected_models = elo_rank_system.sample_next_match()
133
 
134
+ if not selected_models or len(selected_models) != 2:
135
+ return jsonify({"message": "Error selecting models"}), 500
136
+
137
  # Serve test data with the two selected models
138
  current_test = test_data[current_index]
139
  session['selected_models'] = selected_models