Spaces:
Build error
Build error
Commit
·
32c34d8
1
Parent(s):
18c29c2
update
Browse files- app.py +6 -10
- templates/experiment.html +8 -2
app.py
CHANGED
|
@@ -139,7 +139,6 @@ def index():
|
|
| 139 |
from bs4 import BeautifulSoup
|
| 140 |
import re
|
| 141 |
|
| 142 |
-
|
| 143 |
def modify_plan_of_sqls_html(html_content):
|
| 144 |
soup = BeautifulSoup(html_content, 'html.parser')
|
| 145 |
|
|
@@ -150,7 +149,6 @@ def modify_plan_of_sqls_html(html_content):
|
|
| 150 |
|
| 151 |
return str(soup)
|
| 152 |
|
| 153 |
-
|
| 154 |
@app.route('/experiment/<username>', methods=['GET', 'POST'])
|
| 155 |
def experiment(username):
|
| 156 |
try:
|
|
@@ -169,16 +167,14 @@ def experiment(username):
|
|
| 169 |
sample = selected_samples[current_index]
|
| 170 |
visualization_path = f"{VISUALIZATION_DIRS[method]}/{sample['category']}/{sample['file']}"
|
| 171 |
|
| 172 |
-
#
|
| 173 |
if method == 'Plan-of-SQLs':
|
| 174 |
with open(visualization_path, 'r', encoding='utf-8') as file:
|
| 175 |
html_content = file.read()
|
| 176 |
modified_html = modify_plan_of_sqls_html(html_content)
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
file.write(modified_html)
|
| 181 |
-
visualization_path = temp_path
|
| 182 |
|
| 183 |
statement = """
|
| 184 |
Based on the explanation provided, what do you think the AI model will predict?
|
|
@@ -188,14 +184,14 @@ Will it predict the statement as TRUE or FALSE?
|
|
| 188 |
return render_template('experiment.html',
|
| 189 |
sample_id=current_index,
|
| 190 |
statement=statement,
|
| 191 |
-
visualization=url_for('send_visualization', filename=visualization_path),
|
|
|
|
| 192 |
username=username,
|
| 193 |
method=method)
|
| 194 |
except Exception as e:
|
| 195 |
logger.exception(f"An error occurred in the experiment route: {e}")
|
| 196 |
return "An error occurred", 500
|
| 197 |
|
| 198 |
-
|
| 199 |
@app.route('/feedback', methods=['POST'])
|
| 200 |
def feedback():
|
| 201 |
try:
|
|
|
|
| 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 |
|
|
|
|
| 149 |
|
| 150 |
return str(soup)
|
| 151 |
|
|
|
|
| 152 |
@app.route('/experiment/<username>', methods=['GET', 'POST'])
|
| 153 |
def experiment(username):
|
| 154 |
try:
|
|
|
|
| 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 |
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:
|
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,7 +79,13 @@
|
|
| 79 |
<p><strong>Task description:</strong> {{ statement }}</p>
|
| 80 |
</div>
|
| 81 |
<div class="visualization-container">
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
</div>
|
| 84 |
<div class="buttons">
|
| 85 |
<form action="{{ url_for('feedback') }}" method="post">
|
|
|
|
| 35 |
display: flex;
|
| 36 |
justify-content: center;
|
| 37 |
align-items: center;
|
| 38 |
+
overflow: auto;
|
| 39 |
}
|
| 40 |
iframe {
|
| 41 |
width: 100%;
|
|
|
|
| 79 |
<p><strong>Task description:</strong> {{ statement }}</p>
|
| 80 |
</div>
|
| 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 %}
|
| 89 |
</div>
|
| 90 |
<div class="buttons">
|
| 91 |
<form action="{{ url_for('feedback') }}" method="post">
|