luulinh90s commited on
Commit
fb84ce8
·
1 Parent(s): d72e943
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -109,7 +109,6 @@ def 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('/experiment/<username>/<sample_index>/<seed>/<filename>', methods=['GET'])
114
  def experiment(username, sample_index, seed, filename):
115
  try:
@@ -139,10 +138,10 @@ def experiment(username, sample_index, seed, filename):
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.")
@@ -152,12 +151,20 @@ def experiment(username, sample_index, seed, filename):
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
160
 
 
161
  @app.route('/feedback', methods=['POST'])
162
  def feedback():
163
  try:
 
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
  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
 
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,
162
+ filename=filename)
163
  except Exception as e:
164
  logger.exception(f"An error occurred in the experiment route: {e}")
165
  return "An error occurred", 500
166
 
167
+
168
  @app.route('/feedback', methods=['POST'])
169
  def feedback():
170
  try: