Upload index.py
Browse files
index.py
CHANGED
@@ -3,9 +3,13 @@ import requests
|
|
3 |
import json
|
4 |
import time
|
5 |
import random
|
|
|
6 |
import os
|
7 |
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
TRANSITION_MESSAGES = [
|
11 |
"Now we are moving onto question {number}!",
|
@@ -112,72 +116,64 @@ if "session_state" not in st.session_state:
|
|
112 |
st.session_state.prev_question = ""
|
113 |
st.session_state.question_number = 1
|
114 |
|
115 |
-
|
116 |
-
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
st.
|
125 |
-
|
126 |
-
st.
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
start_registration
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
st.
|
140 |
-
|
141 |
-
st.
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
else:
|
153 |
-
|
154 |
-
with st.form(key=f"question_form_{st.session_state.question_number}"):
|
155 |
-
if st.session_state.feedback:
|
156 |
-
st.error(st.session_state.feedback)
|
157 |
-
if st.session_state.prev_question and st.session_state.prev_question != st.session_state.current_question:
|
158 |
-
transition_msg = random.choice(TRANSITION_MESSAGES).format(number=st.session_state.question_number)
|
159 |
-
st.info(transition_msg)
|
160 |
-
time.sleep(1)
|
161 |
-
print(f"Displaying question: {st.session_state.current_question}")
|
162 |
-
st.subheader(f"Question {st.session_state.question_number}: {st.session_state.current_question}")
|
163 |
-
|
164 |
-
is_address_question = st.session_state.current_question == "What is your address?"
|
165 |
-
is_phone_question = st.session_state.current_question == "What is your phone number?"
|
166 |
-
|
167 |
-
if is_address_question or is_phone_question:
|
168 |
-
st.info(
|
169 |
-
f"This question is optional. Check the box to skip, or enter your information below.\n"
|
170 |
-
f"- For address: Include house number (e.g., 123), street name (e.g., High Street), town/city (e.g., London), and postcode (e.g., SW1A 1AA). Example: 123 High Street, London, SW1A 1AA.\n"
|
171 |
-
f"- For phone: Use 10 digits for landlines (e.g., 020 123 4567) or 11 digits for mobiles starting with 07 (e.g., 07700 900 123). Do not use +44 or other region numbers."
|
172 |
-
)
|
173 |
-
if is_address_question:
|
174 |
-
st.session_state.skip_address = st.checkbox("Skip this question", value=st.session_state.skip_address)
|
175 |
-
elif is_phone_question:
|
176 |
-
st.session_state.skip_phone = st.checkbox("Skip this question", value=st.session_state.skip_phone)
|
177 |
-
|
178 |
-
st.session_state.answer = st.text_input("Your Answer", value="", key=f"answer_input_{st.session_state.question_number}")
|
179 |
-
|
180 |
-
if st.form_submit_button("Submit", key="submit_button"):
|
181 |
-
submit_response()
|
182 |
-
else:
|
183 |
-
print("Waiting for session to initialize...")
|
|
|
3 |
import json
|
4 |
import time
|
5 |
import random
|
6 |
+
from dotenv import load_dotenv
|
7 |
import os
|
8 |
|
9 |
+
|
10 |
+
|
11 |
+
load_dotenv()
|
12 |
+
API_URL = os.getenv("API_URL", "http://localhost:8000")
|
13 |
|
14 |
TRANSITION_MESSAGES = [
|
15 |
"Now we are moving onto question {number}!",
|
|
|
116 |
st.session_state.prev_question = ""
|
117 |
st.session_state.question_number = 1
|
118 |
|
119 |
+
if st.session_state.session_id is None:
|
120 |
+
start_registration()
|
121 |
|
122 |
+
st.title("AI-Powered Registration System")
|
123 |
+
|
124 |
+
if st.session_state.summary:
|
125 |
+
st.success("Registration Complete!")
|
126 |
+
st.subheader("Summary")
|
127 |
+
for key, value in st.session_state.summary.items():
|
128 |
+
st.write(f"**{key}**: {value}")
|
129 |
+
new_value = st.text_input(f"Edit {key}", key=f"edit_{key}")
|
130 |
+
if st.button(f"Update {key}", key=f"update_{key}"):
|
131 |
+
edit_field(key, new_value)
|
132 |
+
col1, col2 = st.columns(2)
|
133 |
+
with col1:
|
134 |
+
if st.button("Next Registration", key="next_reg", on_click=start_registration):
|
135 |
+
pass
|
136 |
+
with col2:
|
137 |
+
if st.button("End Session", key="end_sess", on_click=start_registration):
|
138 |
+
pass
|
139 |
+
else:
|
140 |
+
if st.session_state.current_question:
|
141 |
+
if st.session_state.feedback:
|
142 |
+
st.error(st.session_state.feedback)
|
143 |
+
if st.session_state.prev_question and st.session_state.prev_question != st.session_state.current_question:
|
144 |
+
transition_msg = random.choice(TRANSITION_MESSAGES).format(number=st.session_state.question_number)
|
145 |
+
st.info(transition_msg)
|
146 |
+
time.sleep(1)
|
147 |
+
print(f"Displaying question: {st.session_state.current_question}")
|
148 |
+
st.subheader(f"Question {st.session_state.question_number}: {st.session_state.current_question}")
|
149 |
+
|
150 |
+
is_address_question = st.session_state.current_question == "What is your address?"
|
151 |
+
is_phone_question = st.session_state.current_question == "What is your phone number?"
|
152 |
+
|
153 |
+
if is_address_question or is_phone_question:
|
154 |
+
st.info(
|
155 |
+
f"This question is optional. Check the box to skip, or enter your information below.\n"
|
156 |
+
f"- For address: Include house number (e.g., 123), street name (e.g., High Street), town/city (e.g., London), and postcode (e.g., SW1A 1AA). Example: 123 High Street, London, SW1A 1AA.\n"
|
157 |
+
f"- For phone: Use 10 digits for landlines (e.g., 020 123 4567) or 11 digits for mobiles starting with 07 (e.g., 07700 900 123). Do not use +44 or other region numbers."
|
158 |
+
)
|
159 |
+
if is_address_question:
|
160 |
+
st.session_state.skip_address = st.checkbox("Skip this question", value=st.session_state.skip_address)
|
161 |
+
elif is_phone_question:
|
162 |
+
st.session_state.skip_phone = st.checkbox("Skip this question", value=st.session_state.skip_phone)
|
163 |
+
|
164 |
+
st.components.v1.html("""
|
165 |
+
document.addEventListener('keypress', function(e) {
|
166 |
+
if (e.key === 'Enter' && document.activeElement.tagName === 'INPUT') {
|
167 |
+
e.preventDefault();
|
168 |
+
const submitButton = document.querySelector('button[key="submit_button"]');
|
169 |
+
if (submitButton && !submitButton.disabled) submitButton.click();
|
170 |
+
}
|
171 |
+
});
|
172 |
+
""", height=0)
|
173 |
+
|
174 |
+
st.session_state.answer = st.text_input("Your Answer", value="", key=f"answer_input_{st.session_state.question_number}")
|
175 |
+
|
176 |
+
if st.button("Submit", key="submit_button"):
|
177 |
+
submit_response()
|
178 |
else:
|
179 |
+
print("Waiting for session to initialize...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|