Entz commited on
Commit
d0b32da
·
verified ·
1 Parent(s): e188a38

Upload index.py

Browse files
Files changed (1) hide show
  1. index.py +64 -68
index.py CHANGED
@@ -3,9 +3,13 @@ import requests
3
  import json
4
  import time
5
  import random
 
6
  import os
7
 
8
- API_URL = os.getenv("API_URL")
 
 
 
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
- # Create two tabs
116
- tab1, tab2 = st.tabs(["Introduction", "Registration"])
117
 
118
- # Tab 1: Introduction
119
- with tab1:
120
- st.header("Welcome to the AI-Powered Registration System")
121
- try:
122
- with open("tab1.txt", "r") as file:
123
- intro_content = file.read()
124
- st.markdown(intro_content)
125
- except FileNotFoundError:
126
- st.error("Introduction file (tab1.txt) not found. Please create the file with the introduction content.")
127
- except Exception as e:
128
- st.error(f"Error reading introduction file: {e}")
129
-
130
- # Tab 2: Registration App
131
- with tab2:
132
- if st.session_state.session_id is None:
133
- start_registration()
134
-
135
- st.title("AI-Powered Registration System")
136
-
137
- if st.session_state.summary:
138
- st.success("Registration Complete!")
139
- st.subheader("Summary")
140
- for key, value in st.session_state.summary.items():
141
- st.write(f"**{key}**: {value}")
142
- new_value = st.text_input(f"Edit {key}", key=f"edit_{key}")
143
- if st.button(f"Update {key}", key=f"update_{key}"):
144
- edit_field(key, new_value)
145
- col1, col2 = st.columns(2)
146
- with col1:
147
- if st.button("Next Registration", key="next_reg", on_click=start_registration):
148
- pass
149
- with col2:
150
- if st.button("End Session", key="end_sess", on_click=start_registration):
151
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  else:
153
- if st.session_state.current_question:
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...")