luulinh90s commited on
Commit
39152fd
1 Parent(s): fb84ce8
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -109,6 +109,11 @@ def index():
109
  logger.exception(f"Error in index route: {e}")
110
  return "An error occurred", 500
111
  return render_template('index.html')
 
 
 
 
 
112
  @app.route('/experiment/<username>/<sample_index>/<seed>/<filename>', methods=['GET'])
113
  def experiment(username, sample_index, seed, filename):
114
  try:
@@ -138,10 +143,10 @@ def experiment(username, sample_index, seed, filename):
138
  else:
139
  vis_dir = 'visualizations'
140
 
141
- # Construct the relative path to the static directory
142
  for category, dir_path in (VISUALIZATION_DIRS_CHAIN_OF_TABLE if method == "Chain-of-Table" else VISUALIZATION_DIRS_PLAN_OF_SQLS).items():
143
  if visualization_file in os.listdir(dir_path):
144
- visualization_path = f'static/{vis_dir}/{category}/{visualization_file}'
145
  break
146
  else:
147
  logger.error(f"Visualization file {visualization_file} not found.")
@@ -151,11 +156,11 @@ def experiment(username, sample_index, seed, filename):
151
 
152
  statement = "Please make a decision to Accept/Reject the AI prediction based on the explanation."
153
 
154
- # Render the template with the correct path for the iframe
155
  return render_template('experiment.html',
156
  sample_id=sample_index,
157
  statement=statement,
158
- visualization=url_for('static', filename=f'{vis_dir}/{category}/{visualization_file}'),
159
  username=username,
160
  seed=seed,
161
  sample_index=sample_index,
 
109
  logger.exception(f"Error in index route: {e}")
110
  return "An error occurred", 500
111
  return render_template('index.html')
112
+
113
+ @app.route('/visualization/<path:filename>')
114
+ def send_visualization(filename):
115
+ return send_from_directory('visualizations', filename)
116
+
117
  @app.route('/experiment/<username>/<sample_index>/<seed>/<filename>', methods=['GET'])
118
  def experiment(username, sample_index, seed, filename):
119
  try:
 
143
  else:
144
  vis_dir = 'visualizations'
145
 
146
+ # Determine the correct visualization directory based on the category
147
  for category, dir_path in (VISUALIZATION_DIRS_CHAIN_OF_TABLE if method == "Chain-of-Table" else VISUALIZATION_DIRS_PLAN_OF_SQLS).items():
148
  if visualization_file in os.listdir(dir_path):
149
+ visualization_path = f'{category}/{visualization_file}'
150
  break
151
  else:
152
  logger.error(f"Visualization file {visualization_file} not found.")
 
156
 
157
  statement = "Please make a decision to Accept/Reject the AI prediction based on the explanation."
158
 
159
+ # Use the custom route to serve the visualization
160
  return render_template('experiment.html',
161
  sample_id=sample_index,
162
  statement=statement,
163
+ visualization=url_for('send_visualization', filename=visualization_path),
164
  username=username,
165
  seed=seed,
166
  sample_index=sample_index,