luulinh90s
commited on
Commit
•
d421cc0
1
Parent(s):
591d3f0
update
Browse files- app.py +31 -2
- requirements.txt +2 -1
- templates/index.html +15 -9
app.py
CHANGED
@@ -6,6 +6,7 @@ import string
|
|
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,11 +135,29 @@ def index():
|
|
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,8 +168,18 @@ def experiment(username):
|
|
149 |
return redirect(url_for('completed', username=username))
|
150 |
|
151 |
sample = selected_samples[current_index]
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
statement = """
|
156 |
Based on the explanation provided, what do you think the AI model will predict?
|
|
|
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 |
return "An error occurred", 500
|
136 |
return render_template('index.html')
|
137 |
|
138 |
+
|
139 |
+
def modify_plan_of_sqls_html(html_content):
|
140 |
+
soup = BeautifulSoup(html_content, 'html.parser')
|
141 |
+
|
142 |
+
# Remove the final table
|
143 |
+
final_table = soup.find('table', {'class': 'table-auto'})
|
144 |
+
if final_table:
|
145 |
+
final_table.decompose()
|
146 |
+
|
147 |
+
# Remove the Prediction line
|
148 |
+
prediction_p = soup.find('p', string=lambda text: 'Prediction:' in text if text else False)
|
149 |
+
if prediction_p:
|
150 |
+
prediction_p.decompose()
|
151 |
+
|
152 |
+
return str(soup)
|
153 |
+
|
154 |
+
|
155 |
@app.route('/experiment/<username>', methods=['GET', 'POST'])
|
156 |
def experiment(username):
|
157 |
try:
|
158 |
session_data = load_session_data(username)
|
159 |
if not session_data:
|
160 |
+
logger.error(f"Failed to load session data for user: {username}")
|
161 |
return redirect(url_for('index'))
|
162 |
|
163 |
selected_samples = session_data['selected_samples']
|
|
|
168 |
return redirect(url_for('completed', username=username))
|
169 |
|
170 |
sample = selected_samples[current_index]
|
171 |
+
visualization_path = f"{VISUALIZATION_DIRS[method]}/{sample['category']}/{sample['file']}"
|
172 |
+
|
173 |
+
# Modify the HTML content for Plan-of-SQLs
|
174 |
+
if method == 'Plan-of-SQLs':
|
175 |
+
with open(visualization_path, 'r') as file:
|
176 |
+
html_content = file.read()
|
177 |
+
modified_html = modify_plan_of_sqls_html(html_content)
|
178 |
+
# Save the modified HTML to a temporary file
|
179 |
+
temp_path = f"/tmp/{sample['file']}"
|
180 |
+
with open(temp_path, 'w') as file:
|
181 |
+
file.write(modified_html)
|
182 |
+
visualization_path = temp_path
|
183 |
|
184 |
statement = """
|
185 |
Based on the explanation provided, what do you think the AI model will predict?
|
requirements.txt
CHANGED
@@ -6,4 +6,5 @@ jinja2==3.1.4
|
|
6 |
numpy==1.23.3
|
7 |
scipy==1.9.3
|
8 |
flask_session==0.8.0
|
9 |
-
redis
|
|
|
|
6 |
numpy==1.23.3
|
7 |
scipy==1.9.3
|
8 |
flask_session==0.8.0
|
9 |
+
redis
|
10 |
+
beautifulsoup4
|
templates/index.html
CHANGED
@@ -58,19 +58,19 @@
|
|
58 |
font-weight: bold;
|
59 |
text-align: center;
|
60 |
}
|
61 |
-
.method-button.
|
62 |
background-color: #e0f0ff;
|
63 |
color: #1e90ff;
|
64 |
}
|
65 |
-
.method-button.
|
66 |
background-color: #ffcc80;
|
67 |
color: #e65100;
|
68 |
}
|
69 |
-
.method-button.
|
70 |
background-color: #e8f5e9;
|
71 |
color: #4caf50;
|
72 |
}
|
73 |
-
.method-button.
|
74 |
background-color: #fff3e0;
|
75 |
color: #ff9800;
|
76 |
}
|
@@ -81,6 +81,12 @@
|
|
81 |
border-color: #000000;
|
82 |
box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
|
83 |
transform: scale(1.05);
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
}
|
85 |
button[type="submit"] {
|
86 |
background-color: #4CAF50;
|
@@ -106,7 +112,7 @@
|
|
106 |
buttons[i].classList.remove('selected');
|
107 |
}
|
108 |
|
109 |
-
var selectedButton = document.querySelector(
|
110 |
if (selectedButton) {
|
111 |
selectedButton.classList.add('selected');
|
112 |
}
|
@@ -137,16 +143,16 @@
|
|
137 |
<input type="hidden" id="method" name="method" required>
|
138 |
|
139 |
<div class="method-buttons">
|
140 |
-
<div class="method-button
|
141 |
Chain-of-Table
|
142 |
</div>
|
143 |
-
<div class="method-button
|
144 |
Plan-of-SQLs
|
145 |
</div>
|
146 |
-
<div class="method-button
|
147 |
Dater
|
148 |
</div>
|
149 |
-
<div class="method-button
|
150 |
No-XAI
|
151 |
</div>
|
152 |
</div>
|
|
|
58 |
font-weight: bold;
|
59 |
text-align: center;
|
60 |
}
|
61 |
+
.method-button.Chain-of-Table {
|
62 |
background-color: #e0f0ff;
|
63 |
color: #1e90ff;
|
64 |
}
|
65 |
+
.method-button.Plan-of-SQLs {
|
66 |
background-color: #ffcc80;
|
67 |
color: #e65100;
|
68 |
}
|
69 |
+
.method-button.Dater {
|
70 |
background-color: #e8f5e9;
|
71 |
color: #4caf50;
|
72 |
}
|
73 |
+
.method-button.No-XAI {
|
74 |
background-color: #fff3e0;
|
75 |
color: #ff9800;
|
76 |
}
|
|
|
81 |
border-color: #000000;
|
82 |
box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
|
83 |
transform: scale(1.05);
|
84 |
+
animation: borderPulse 0.5s ease-in-out;
|
85 |
+
}
|
86 |
+
@keyframes borderPulse {
|
87 |
+
0% { border-color: transparent; }
|
88 |
+
50% { border-color: #000000; }
|
89 |
+
100% { border-color: #000000; }
|
90 |
}
|
91 |
button[type="submit"] {
|
92 |
background-color: #4CAF50;
|
|
|
112 |
buttons[i].classList.remove('selected');
|
113 |
}
|
114 |
|
115 |
+
var selectedButton = document.querySelector(`.method-button.${method}`);
|
116 |
if (selectedButton) {
|
117 |
selectedButton.classList.add('selected');
|
118 |
}
|
|
|
143 |
<input type="hidden" id="method" name="method" required>
|
144 |
|
145 |
<div class="method-buttons">
|
146 |
+
<div class="method-button Chain-of-Table" onclick="selectMethod('Chain-of-Table')">
|
147 |
Chain-of-Table
|
148 |
</div>
|
149 |
+
<div class="method-button Plan-of-SQLs" onclick="selectMethod('Plan-of-SQLs')">
|
150 |
Plan-of-SQLs
|
151 |
</div>
|
152 |
+
<div class="method-button Dater" onclick="selectMethod('Dater')">
|
153 |
Dater
|
154 |
</div>
|
155 |
+
<div class="method-button No-XAI" onclick="selectMethod('No-XAI')">
|
156 |
No-XAI
|
157 |
</div>
|
158 |
</div>
|