luulinh90s commited on
Commit
6103c97
1 Parent(s): 497f14e
Files changed (1) hide show
  1. app.py +18 -42
app.py CHANGED
@@ -3,7 +3,6 @@ import json
3
  import random
4
  import os
5
  import string
6
- from flask_session import Session
7
  import logging
8
 
9
  # Set up logging
@@ -17,8 +16,6 @@ logger = logging.getLogger(__name__)
17
 
18
  app = Flask(__name__)
19
  app.config['SECRET_KEY'] = 'supersecretkey' # Change this to a random secret key
20
- app.config['SESSION_TYPE'] = 'redis'
21
- Session(app)
22
 
23
  # Directories for visualizations
24
  VISUALIZATION_DIRS_PLAN_OF_SQLS = {
@@ -99,7 +96,10 @@ def index():
99
 
100
  logger.info(f"Generated filename: {filename}")
101
 
102
- session['selected_samples'] = selected_samples
 
 
 
103
  session['responses'] = [] # Initialize responses list
104
  session['method'] = method # Store the selected method
105
 
@@ -108,11 +108,17 @@ def index():
108
  logger.exception(f"Error in index route: {e}")
109
  return "An error occurred", 500
110
  return render_template('index.html')
 
 
111
  @app.route('/experiment/<username>/<sample_index>/<seed>/<filename>', methods=['GET'])
112
  def experiment(username, sample_index, seed, filename):
113
  try:
114
  sample_index = int(sample_index)
115
- selected_samples = session.get('selected_samples', [])
 
 
 
 
116
  method = session.get('method') # Retrieve the selected method
117
 
118
  if sample_index >= len(selected_samples):
@@ -154,21 +160,6 @@ def experiment(username, sample_index, seed, filename):
154
  return "An error occurred", 500
155
 
156
 
157
- @app.route('/visualizations/<path:path>')
158
- def send_visualization(path):
159
- try:
160
- method = session.get('method')
161
- if method == "Chain-of-Table":
162
- visualization_dir = 'htmls_COT'
163
- else: # Default to Plan-of-SQLs
164
- visualization_dir = 'visualizations'
165
-
166
- return send_from_directory(visualization_dir, path)
167
- except Exception as e:
168
- logger.exception(f"Error sending visualization: {e}")
169
- return "An error occurred", 500
170
-
171
-
172
  @app.route('/feedback', methods=['POST'])
173
  def feedback():
174
  try:
@@ -179,7 +170,10 @@ def feedback():
179
  sample_index = int(request.form['sample_index'])
180
  filename = request.form['filename']
181
 
182
- selected_samples = session.get('selected_samples', [])
 
 
 
183
  responses = session.get('responses', [])
184
 
185
  responses.append({
@@ -227,6 +221,7 @@ def completed(filename):
227
  try:
228
  responses = session.get('responses', [])
229
  method = session.get('method')
 
230
  if method == "Chain-of-Table":
231
  json_file = 'Tabular_LLMs_human_study_vis_6_COT.json'
232
  else: # Default to Plan-of-SQLs
@@ -254,8 +249,7 @@ def completed(filename):
254
  else:
255
  ground_truth_key = f"POS_test-{index}.html"
256
 
257
- if ground_truth_key in ground_truth and ground_truth[ground_truth_key][
258
- 'answer'].upper() == feedback.upper():
259
  correct_responses += 1
260
  else:
261
  logger.warning(f"Missing or mismatched key: {ground_truth_key}")
@@ -278,24 +272,6 @@ def completed(filename):
278
  return "An error occurred", 500
279
 
280
 
281
- # if __name__ == '__main__':
282
- # try:
283
- # app.run(debug=False, port=7860)
284
- # except Exception as e:
285
- # logger.exception(f"Failed to start app: {e}")
286
-
287
-
288
- # from flask import Flask
289
- #
290
- # app = Flask(__name__)
291
- #
292
- # @app.route('/')
293
- # def index():
294
- # return "Hello, world!"
295
-
296
- # if __name__ == '__main__':
297
- # app.run(debug=False, port=7860)
298
-
299
  if __name__ == "__main__":
 
300
  app.run(host="0.0.0.0", port=7860)
301
-
 
3
  import random
4
  import os
5
  import string
 
6
  import logging
7
 
8
  # Set up logging
 
16
 
17
  app = Flask(__name__)
18
  app.config['SECRET_KEY'] = 'supersecretkey' # Change this to a random secret key
 
 
19
 
20
  # Directories for visualizations
21
  VISUALIZATION_DIRS_PLAN_OF_SQLS = {
 
96
 
97
  logger.info(f"Generated filename: {filename}")
98
 
99
+ # Save selected samples to a JSON file
100
+ with open(f'session_data/{filename}', 'w') as f:
101
+ json.dump(selected_samples, f)
102
+
103
  session['responses'] = [] # Initialize responses list
104
  session['method'] = method # Store the selected method
105
 
 
108
  logger.exception(f"Error in index route: {e}")
109
  return "An error occurred", 500
110
  return render_template('index.html')
111
+
112
+
113
  @app.route('/experiment/<username>/<sample_index>/<seed>/<filename>', methods=['GET'])
114
  def experiment(username, sample_index, seed, filename):
115
  try:
116
  sample_index = int(sample_index)
117
+
118
+ # Load selected samples from the JSON file
119
+ with open(f'session_data/{filename}', 'r') as f:
120
+ selected_samples = json.load(f)
121
+
122
  method = session.get('method') # Retrieve the selected method
123
 
124
  if sample_index >= len(selected_samples):
 
160
  return "An error occurred", 500
161
 
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  @app.route('/feedback', methods=['POST'])
164
  def feedback():
165
  try:
 
170
  sample_index = int(request.form['sample_index'])
171
  filename = request.form['filename']
172
 
173
+ # Load selected samples from the JSON file
174
+ with open(f'session_data/{filename}', 'r') as f:
175
+ selected_samples = json.load(f)
176
+
177
  responses = session.get('responses', [])
178
 
179
  responses.append({
 
221
  try:
222
  responses = session.get('responses', [])
223
  method = session.get('method')
224
+
225
  if method == "Chain-of-Table":
226
  json_file = 'Tabular_LLMs_human_study_vis_6_COT.json'
227
  else: # Default to Plan-of-SQLs
 
249
  else:
250
  ground_truth_key = f"POS_test-{index}.html"
251
 
252
+ if ground_truth_key in ground_truth and ground_truth[ground_truth_key]['answer'].upper() == feedback.upper():
 
253
  correct_responses += 1
254
  else:
255
  logger.warning(f"Missing or mismatched key: {ground_truth_key}")
 
272
  return "An error occurred", 500
273
 
274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  if __name__ == "__main__":
276
+ os.makedirs('session_data', exist_ok=True) # Ensure the directory for session files exists
277
  app.run(host="0.0.0.0", port=7860)