luulinh90s
commited on
Commit
·
5d0030d
1
Parent(s):
b05a860
update
Browse files- app.py +3 -23
- templates/experiment.html +2 -6
app.py
CHANGED
@@ -6,7 +6,6 @@ import string
|
|
6 |
import logging
|
7 |
from datetime import datetime
|
8 |
from huggingface_hub import login, HfApi, hf_hub_download
|
9 |
-
from bs4 import BeautifulSoup
|
10 |
|
11 |
# Set up logging
|
12 |
logging.basicConfig(level=logging.INFO,
|
@@ -135,25 +134,11 @@ def index():
|
|
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()
|
148 |
-
|
149 |
-
return str(soup)
|
150 |
-
|
151 |
@app.route('/experiment/<username>', methods=['GET', 'POST'])
|
152 |
def experiment(username):
|
153 |
try:
|
154 |
session_data = load_session_data(username)
|
155 |
if not session_data:
|
156 |
-
logger.error(f"Failed to load session data for user: {username}")
|
157 |
return redirect(url_for('index'))
|
158 |
|
159 |
selected_samples = session_data['selected_samples']
|
@@ -164,12 +149,8 @@ def experiment(username):
|
|
164 |
return redirect(url_for('completed', username=username))
|
165 |
|
166 |
sample = selected_samples[current_index]
|
167 |
-
|
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,7 +160,7 @@ Will it predict the statement as TRUE or FALSE?
|
|
179 |
return render_template('experiment.html',
|
180 |
sample_id=current_index,
|
181 |
statement=statement,
|
182 |
-
|
183 |
username=username,
|
184 |
method=method)
|
185 |
except Exception as e:
|
@@ -187,7 +168,6 @@ Will it predict the statement as TRUE or FALSE?
|
|
187 |
return "An error occurred", 500
|
188 |
|
189 |
|
190 |
-
|
191 |
@app.route('/feedback', methods=['POST'])
|
192 |
def feedback():
|
193 |
try:
|
|
|
6 |
import logging
|
7 |
from datetime import datetime
|
8 |
from huggingface_hub import login, HfApi, hf_hub_download
|
|
|
9 |
|
10 |
# Set up logging
|
11 |
logging.basicConfig(level=logging.INFO,
|
|
|
134 |
return "An error occurred", 500
|
135 |
return render_template('index.html')
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
@app.route('/experiment/<username>', methods=['GET', 'POST'])
|
138 |
def experiment(username):
|
139 |
try:
|
140 |
session_data = load_session_data(username)
|
141 |
if not session_data:
|
|
|
142 |
return redirect(url_for('index'))
|
143 |
|
144 |
selected_samples = session_data['selected_samples']
|
|
|
149 |
return redirect(url_for('completed', username=username))
|
150 |
|
151 |
sample = selected_samples[current_index]
|
152 |
+
visualization_dir = VISUALIZATION_DIRS[method]
|
153 |
+
visualization_path = f"{visualization_dir}/{sample['category']}/{sample['file']}"
|
|
|
|
|
|
|
|
|
154 |
|
155 |
statement = """
|
156 |
Based on the explanation provided, what do you think the AI model will predict?
|
|
|
160 |
return render_template('experiment.html',
|
161 |
sample_id=current_index,
|
162 |
statement=statement,
|
163 |
+
visualization=url_for('send_visualization', filename=visualization_path),
|
164 |
username=username,
|
165 |
method=method)
|
166 |
except Exception as e:
|
|
|
168 |
return "An error occurred", 500
|
169 |
|
170 |
|
|
|
171 |
@app.route('/feedback', methods=['POST'])
|
172 |
def feedback():
|
173 |
try:
|
templates/experiment.html
CHANGED
@@ -35,7 +35,7 @@
|
|
35 |
display: flex;
|
36 |
justify-content: center;
|
37 |
align-items: center;
|
38 |
-
overflow:
|
39 |
}
|
40 |
iframe {
|
41 |
width: 100%;
|
@@ -79,11 +79,7 @@
|
|
79 |
<p><strong>Task description:</strong> {{ statement }}</p>
|
80 |
</div>
|
81 |
<div class="visualization-container">
|
82 |
-
{
|
83 |
-
<div>{{ visualization_content | safe }}</div>
|
84 |
-
{% else %}
|
85 |
-
<p>No visualization available.</p>
|
86 |
-
{% endif %}
|
87 |
</div>
|
88 |
<div class="buttons">
|
89 |
<form action="{{ url_for('feedback') }}" method="post">
|
|
|
35 |
display: flex;
|
36 |
justify-content: center;
|
37 |
align-items: center;
|
38 |
+
overflow: hidden;
|
39 |
}
|
40 |
iframe {
|
41 |
width: 100%;
|
|
|
79 |
<p><strong>Task description:</strong> {{ statement }}</p>
|
80 |
</div>
|
81 |
<div class="visualization-container">
|
82 |
+
<iframe src="{{ visualization }}"></iframe>
|
|
|
|
|
|
|
|
|
83 |
</div>
|
84 |
<div class="buttons">
|
85 |
<form action="{{ url_for('feedback') }}" method="post">
|