luulinh90s commited on
Commit
d72e943
·
1 Parent(s): 4c76f52
Files changed (1) hide show
  1. app.py +10 -34
app.py CHANGED
@@ -133,50 +133,27 @@ def experiment(username, sample_index, seed, filename):
133
  return redirect(url_for('completed', filename=filename))
134
 
135
  visualization_file = selected_samples[sample_index]
136
- visualization_path = None
137
-
138
- # Determine the correct visualization directory based on the method
139
- # if method == "Chain-of-Table":
140
- # visualization_dirs = VISUALIZATION_DIRS_CHAIN_OF_TABLE
141
- # else:
142
- # visualization_dirs = VISUALIZATION_DIRS_PLAN_OF_SQLS
143
 
144
  if method == "Chain-of-Table":
145
- visualization_dirs = VISUALIZATION_DIRS_CHAIN_OF_TABLE
146
  vis_dir = 'htmls_COT'
147
  else:
148
- visualization_dirs = VISUALIZATION_DIRS_PLAN_OF_SQLS
149
  vis_dir = 'visualizations'
150
 
151
- logger.info(f"Checking directories for method: {method}")
152
-
153
- # Find the correct visualization path
154
- for category, dir_path in visualization_dirs.items():
155
- absolute_dir_path = os.path.abspath(dir_path)
156
- logger.info(f"Checking directory: {absolute_dir_path} for file: {visualization_file}")
157
- if visualization_file.strip() in os.listdir(absolute_dir_path):
158
- logger.info(f"visualization_file.strip(): {visualization_file.strip()}")
159
- logger.info(f"absolute_dir_path files: {os.listdir(absolute_dir_path)}")
160
-
161
- visualization_path = os.path.abspath(os.path.join(dir_path, visualization_file))
162
  break
163
-
164
- if not visualization_path:
165
- logger.error(
166
- f"Visualization file {visualization_file} not found. Searched path: {absolute_dir_path}/{visualization_file}")
167
  return "Visualization file not found", 404
168
 
169
  logger.info(f"Rendering experiment page with visualization: {visualization_path}")
170
 
171
  statement = "Please make a decision to Accept/Reject the AI prediction based on the explanation."
172
- return render_template('experiment.html',
173
- sample_id=sample_index,
174
- statement=statement,
175
- visualization=visualization_path,
176
- username=username,
177
- seed=seed,
178
- sample_index=sample_index,
179
- filename=filename)
180
  except Exception as e:
181
  logger.exception(f"An error occurred in the experiment route: {e}")
182
  return "An error occurred", 500
@@ -230,8 +207,7 @@ def feedback():
230
  if next_sample_index >= len(selected_samples):
231
  return redirect(url_for('completed', filename=filename))
232
 
233
- return redirect(
234
- url_for('experiment', username=username, sample_index=next_sample_index, seed=seed, filename=filename))
235
  except Exception as e:
236
  logger.exception(f"Error in feedback route: {e}")
237
  return "An error occurred", 500
 
133
  return redirect(url_for('completed', filename=filename))
134
 
135
  visualization_file = selected_samples[sample_index]
 
 
 
 
 
 
 
136
 
137
  if method == "Chain-of-Table":
 
138
  vis_dir = 'htmls_COT'
139
  else:
 
140
  vis_dir = 'visualizations'
141
 
142
+ # Determine the correct visualization directory based on the category
143
+ for category, dir_path in (VISUALIZATION_DIRS_CHAIN_OF_TABLE if method == "Chain-of-Table" else VISUALIZATION_DIRS_PLAN_OF_SQLS).items():
144
+ if visualization_file in os.listdir(dir_path):
145
+ visualization_path = os.path.join(vis_dir, category, visualization_file)
 
 
 
 
 
 
 
146
  break
147
+ else:
148
+ logger.error(f"Visualization file {visualization_file} not found.")
 
 
149
  return "Visualization file not found", 404
150
 
151
  logger.info(f"Rendering experiment page with visualization: {visualization_path}")
152
 
153
  statement = "Please make a decision to Accept/Reject the AI prediction based on the explanation."
154
+
155
+ # Serve the file directly from the directory
156
+ return send_from_directory(directory=os.path.join(os.getcwd(), vis_dir, category), path=visualization_file)
 
 
 
 
 
157
  except Exception as e:
158
  logger.exception(f"An error occurred in the experiment route: {e}")
159
  return "An error occurred", 500
 
207
  if next_sample_index >= len(selected_samples):
208
  return redirect(url_for('completed', filename=filename))
209
 
210
+ return redirect(url_for('experiment', username=username, sample_index=next_sample_index, seed=seed, filename=filename))
 
211
  except Exception as e:
212
  logger.exception(f"Error in feedback route: {e}")
213
  return "An error occurred", 500