luulinh90s commited on
Commit
4600a8b
Β·
1 Parent(s): 2529cfa
Files changed (2) hide show
  1. app.py +17 -7
  2. templates/index.html +12 -9
app.py CHANGED
@@ -156,30 +156,40 @@ def index():
156
  'start_time': start_time,
157
  'session_id': session_id
158
  }
159
- session['data'] = session_data # Store data in session instead of committing
160
- return redirect(url_for('explanation', session_id=session_id))
 
 
 
 
 
 
161
  except Exception as e:
162
  logger.exception(f"Error in index route: {e}")
163
  return render_template('index.html', error="An error occurred. Please try again.")
164
  return render_template('index.html')
165
 
166
-
167
-
168
  @app.route('/explanation/<session_id>')
169
  def explanation(session_id):
170
  session_data = session.get('data')
171
  if not session_data:
 
 
 
 
 
 
172
  return redirect(url_for('index'))
173
 
174
- method = session_data['method']
175
  if method == 'Chain-of-Table':
176
  return render_template('cot_intro.html', session_id=session_id)
177
  elif method == 'Plan-of-SQLs':
178
  return render_template('pos_intro.html', session_id=session_id)
179
  elif method == 'Dater':
180
  return render_template('dater_intro.html', session_id=session_id)
181
- else: # No-XAI
182
- return redirect(url_for('experiment', session_id=session_id))
 
183
 
184
  @app.route('/experiment/<session_id>', methods=['GET', 'POST'])
185
  def experiment(session_id):
 
156
  'start_time': start_time,
157
  'session_id': session_id
158
  }
159
+ session['data'] = session_data # Store data in session
160
+ logger.info(f"Session data stored for user {username}, method {method}")
161
+
162
+ # Redirect based on the selected method
163
+ if method == 'No-XAI':
164
+ return redirect(url_for('experiment', session_id=session_id))
165
+ else:
166
+ return redirect(url_for('explanation', session_id=session_id))
167
  except Exception as e:
168
  logger.exception(f"Error in index route: {e}")
169
  return render_template('index.html', error="An error occurred. Please try again.")
170
  return render_template('index.html')
171
 
 
 
172
  @app.route('/explanation/<session_id>')
173
  def explanation(session_id):
174
  session_data = session.get('data')
175
  if not session_data:
176
+ logger.error(f"No session data found for session ID: {session_id}")
177
+ return redirect(url_for('index'))
178
+
179
+ method = session_data.get('method')
180
+ if not method:
181
+ logger.error(f"No method found in session data for session ID: {session_id}")
182
  return redirect(url_for('index'))
183
 
 
184
  if method == 'Chain-of-Table':
185
  return render_template('cot_intro.html', session_id=session_id)
186
  elif method == 'Plan-of-SQLs':
187
  return render_template('pos_intro.html', session_id=session_id)
188
  elif method == 'Dater':
189
  return render_template('dater_intro.html', session_id=session_id)
190
+ else:
191
+ logger.error(f"Invalid method '{method}' for session ID: {session_id}")
192
+ return redirect(url_for('index'))
193
 
194
  @app.route('/experiment/<session_id>', methods=['GET', 'POST'])
195
  def experiment(session_id):
templates/index.html CHANGED
@@ -74,7 +74,6 @@
74
  background-color: #fff3e0;
75
  color: #ff9800;
76
  }
77
-
78
  .task-instruction {
79
  background-color: #f0f8ff;
80
  border-left: 5px solid #4CAF50;
@@ -101,7 +100,6 @@
101
  font-size: 18px;
102
  color: #333;
103
  }
104
-
105
  .method-button:hover {
106
  opacity: 0.8;
107
  }
@@ -130,6 +128,11 @@
130
  button:hover {
131
  background-color: #45a049;
132
  }
 
 
 
 
 
133
  </style>
134
  <script>
135
  function selectMethod(method) {
@@ -156,12 +159,6 @@
156
  }
157
  return true;
158
  }
159
-
160
- function goToExplanation() {
161
- if (validateForm()) {
162
- document.getElementById('method-form').submit();
163
- }
164
- }
165
  </script>
166
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
167
  </head>
@@ -187,6 +184,12 @@
187
  </div>
188
  </div>
189
 
 
 
 
 
 
 
190
  <form id="method-form" action="{{ url_for('index') }}" method="post" onsubmit="return validateForm();">
191
  <label for="username">Hi there πŸ‘‹πŸ‘‹πŸ‘‹ ! What is your name?</label>
192
  <input type="text" id="username" name="username" required>
@@ -210,7 +213,7 @@
210
  </div>
211
  </div>
212
 
213
- <button type="button" onclick="goToExplanation()">Next</button>
214
  </form>
215
  </div>
216
  </body>
 
74
  background-color: #fff3e0;
75
  color: #ff9800;
76
  }
 
77
  .task-instruction {
78
  background-color: #f0f8ff;
79
  border-left: 5px solid #4CAF50;
 
100
  font-size: 18px;
101
  color: #333;
102
  }
 
103
  .method-button:hover {
104
  opacity: 0.8;
105
  }
 
128
  button:hover {
129
  background-color: #45a049;
130
  }
131
+ .error-message {
132
+ color: red;
133
+ margin-bottom: 10px;
134
+ font-size: 18px;
135
+ }
136
  </style>
137
  <script>
138
  function selectMethod(method) {
 
159
  }
160
  return true;
161
  }
 
 
 
 
 
 
162
  </script>
163
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
164
  </head>
 
184
  </div>
185
  </div>
186
 
187
+ {% if error %}
188
+ <div class="error-message">
189
+ {{ error }}
190
+ </div>
191
+ {% endif %}
192
+
193
  <form id="method-form" action="{{ url_for('index') }}" method="post" onsubmit="return validateForm();">
194
  <label for="username">Hi there πŸ‘‹πŸ‘‹πŸ‘‹ ! What is your name?</label>
195
  <input type="text" id="username" name="username" required>
 
213
  </div>
214
  </div>
215
 
216
+ <button type="submit">Next</button>
217
  </form>
218
  </div>
219
  </body>