luulinh90s commited on
Commit
b05a860
·
1 Parent(s): 32c34d8
Files changed (2) hide show
  1. app.py +9 -13
  2. templates/experiment.html +0 -2
app.py CHANGED
@@ -135,14 +135,13 @@ def index():
135
  return "An error occurred", 500
136
  return render_template('index.html')
137
 
138
-
139
  from bs4 import BeautifulSoup
140
  import re
141
 
142
- def modify_plan_of_sqls_html(html_content):
143
  soup = BeautifulSoup(html_content, 'html.parser')
144
 
145
- # Remove only the Prediction line
146
  prediction_h3 = soup.find('h3', string=re.compile(r'Prediction:'))
147
  if prediction_h3:
148
  prediction_h3.decompose()
@@ -167,14 +166,10 @@ def experiment(username):
167
  sample = selected_samples[current_index]
168
  visualization_path = f"{VISUALIZATION_DIRS[method]}/{sample['category']}/{sample['file']}"
169
 
170
- # For Plan-of-SQLs, modify the HTML content directly
171
- if method == 'Plan-of-SQLs':
172
- with open(visualization_path, 'r', encoding='utf-8') as file:
173
- html_content = file.read()
174
- modified_html = modify_plan_of_sqls_html(html_content)
175
- else:
176
- # For other methods, just use the file path
177
- modified_html = None
178
 
179
  statement = """
180
  Based on the explanation provided, what do you think the AI model will predict?
@@ -184,14 +179,15 @@ Will it predict the statement as TRUE or FALSE?
184
  return render_template('experiment.html',
185
  sample_id=current_index,
186
  statement=statement,
187
- visualization=url_for('send_visualization', filename=visualization_path) if method != 'Plan-of-SQLs' else None,
188
- visualization_content=modified_html if method == 'Plan-of-SQLs' else None,
189
  username=username,
190
  method=method)
191
  except Exception as e:
192
  logger.exception(f"An error occurred in the experiment route: {e}")
193
  return "An error occurred", 500
194
 
 
 
195
  @app.route('/feedback', methods=['POST'])
196
  def feedback():
197
  try:
 
135
  return "An error occurred", 500
136
  return render_template('index.html')
137
 
 
138
  from bs4 import BeautifulSoup
139
  import re
140
 
141
+ def remove_prediction_from_html(html_content):
142
  soup = BeautifulSoup(html_content, 'html.parser')
143
 
144
+ # Remove the Prediction line
145
  prediction_h3 = soup.find('h3', string=re.compile(r'Prediction:'))
146
  if prediction_h3:
147
  prediction_h3.decompose()
 
166
  sample = selected_samples[current_index]
167
  visualization_path = f"{VISUALIZATION_DIRS[method]}/{sample['category']}/{sample['file']}"
168
 
169
+ # Modify the HTML content for all methods
170
+ with open(visualization_path, 'r', encoding='utf-8') as file:
171
+ html_content = file.read()
172
+ modified_html = remove_prediction_from_html(html_content)
 
 
 
 
173
 
174
  statement = """
175
  Based on the explanation provided, what do you think the AI model will predict?
 
179
  return render_template('experiment.html',
180
  sample_id=current_index,
181
  statement=statement,
182
+ visualization_content=modified_html,
 
183
  username=username,
184
  method=method)
185
  except Exception as e:
186
  logger.exception(f"An error occurred in the experiment route: {e}")
187
  return "An error occurred", 500
188
 
189
+
190
+
191
  @app.route('/feedback', methods=['POST'])
192
  def feedback():
193
  try:
templates/experiment.html CHANGED
@@ -81,8 +81,6 @@
81
  <div class="visualization-container">
82
  {% if visualization_content %}
83
  <div>{{ visualization_content | safe }}</div>
84
- {% elif visualization %}
85
- <iframe src="{{ visualization }}"></iframe>
86
  {% else %}
87
  <p>No visualization available.</p>
88
  {% endif %}
 
81
  <div class="visualization-container">
82
  {% if visualization_content %}
83
  <div>{{ visualization_content | safe }}</div>
 
 
84
  {% else %}
85
  <p>No visualization available.</p>
86
  {% endif %}