Entz commited on
Commit
990935d
·
verified ·
1 Parent(s): 4477c62

Upload index.py

Browse files
Files changed (1) hide show
  1. index.py +26 -36
index.py CHANGED
@@ -76,8 +76,8 @@ def submit_response():
76
  if st.session_state.prev_question != st.session_state.current_question:
77
  st.session_state.question_number += 1
78
  st.session_state.answer = ""
79
- st.session_state.skip_address = False
80
- st.session_state.skip_phone = False
81
  st.rerun()
82
  except requests.RequestException as e:
83
  print(f"Error submitting response: {e}")
@@ -111,23 +111,18 @@ def edit_field(field, value):
111
 
112
  def main():
113
  st.title("AI-Powered Registration System")
114
-
115
  # Create two tabs
116
  tab1, tab2 = st.tabs(["Introduction", "Registration"])
117
-
118
  # Tab 1: Introduction
119
  with tab1:
120
- st.subheader("About This Application")
121
  intro_content = read_content_from_file("tab1.txt")
122
  st.markdown(intro_content)
123
-
124
  # Tab 2: Registration Application
125
  with tab2:
126
- # st.subheader("Registration")
127
  registration_content = read_content_from_file("tab2.txt")
128
  st.markdown(registration_content)
129
  st.markdown("**Developed by [email protected]**")
130
-
131
  if st.session_state.get("summary"):
132
  st.success("Registration Complete!")
133
  st.subheader("Summary")
@@ -138,11 +133,15 @@ def main():
138
  edit_field(key, new_value)
139
  col1, col2 = st.columns(2)
140
  with col1:
141
- if st.button("Next Registration", key="next_reg", on_click=start_registration):
142
- pass
143
  with col2:
144
- if st.button("End Session", key="end_sess", on_click=start_registration):
145
- pass
 
 
 
 
146
  else:
147
  if st.session_state.get("current_question"):
148
  if st.session_state.get("feedback"):
@@ -152,42 +151,36 @@ def main():
152
  st.info(transition_msg)
153
  time.sleep(1)
154
  st.subheader(f"Question {st.session_state.question_number}: {st.session_state.current_question}")
155
-
156
  is_address_question = st.session_state.current_question == "What is your address?"
157
  is_phone_question = st.session_state.current_question == "What is your phone number?"
158
-
159
  if is_address_question or is_phone_question:
160
  st.info(
161
  f"This question is optional. Check the box to skip, or enter your information below.\n"
162
  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"
163
  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). Avoid +44 formats."
164
  )
165
- if is_address_question:
166
- st.session_state.skip_address = st.checkbox("Skip this question", value=st.session_state.skip_address)
167
- elif is_phone_question:
168
- st.session_state.skip_phone = st.checkbox("Skip this question", value=st.session_state.skip_phone)
169
-
170
  st.components.v1.html("""
171
- document.addEventListener('keypress', function(e) {
172
- if (e.key === 'Enter' && document.activeElement.tagName === 'INPUT') {
173
- e.preventDefault();
174
- const submitButton = document.querySelector('button[key="submit_button"]');
175
- if (submitButton && !submitButton.disabled) submitButton.click();
176
- }
177
- });
178
  """, height=0)
179
-
180
  st.session_state.answer = st.text_input("Your Answer", value="", key=f"answer_input_{st.session_state.question_number}")
181
-
182
- if st.button("Submit", key="submit_button"):
183
  submit_response()
184
  else:
185
  print("Waiting for session to initialize...")
186
 
187
  if __name__ == "__main__":
188
- # Initialize session state
189
- if "session_state" not in st.session_state:
190
- st.session_state.session_state = {}
191
  st.session_state.session_id = None
192
  st.session_state.current_question = ""
193
  st.session_state.answer = ""
@@ -197,8 +190,5 @@ if __name__ == "__main__":
197
  st.session_state.skip_phone = False
198
  st.session_state.prev_question = ""
199
  st.session_state.question_number = 1
200
-
201
- if st.session_state.session_id is None:
202
  start_registration()
203
-
204
- main()
 
76
  if st.session_state.prev_question != st.session_state.current_question:
77
  st.session_state.question_number += 1
78
  st.session_state.answer = ""
79
+ st.session_state.skip_address = False
80
+ st.session_state.skip_phone = False
81
  st.rerun()
82
  except requests.RequestException as e:
83
  print(f"Error submitting response: {e}")
 
111
 
112
  def main():
113
  st.title("AI-Powered Registration System")
 
114
  # Create two tabs
115
  tab1, tab2 = st.tabs(["Introduction", "Registration"])
 
116
  # Tab 1: Introduction
117
  with tab1:
118
+ # st.subheader("About This Application")
119
  intro_content = read_content_from_file("tab1.txt")
120
  st.markdown(intro_content)
 
121
  # Tab 2: Registration Application
122
  with tab2:
 
123
  registration_content = read_content_from_file("tab2.txt")
124
  st.markdown(registration_content)
125
  st.markdown("**Developed by [email protected]**")
 
126
  if st.session_state.get("summary"):
127
  st.success("Registration Complete!")
128
  st.subheader("Summary")
 
133
  edit_field(key, new_value)
134
  col1, col2 = st.columns(2)
135
  with col1:
136
+ if st.button("Next Registration", key="next_reg"):
137
+ start_registration()
138
  with col2:
139
+ if st.button("End Session", key="end_sess"):
140
+ # Custom logic for ending session can be added here
141
+ st.session_state.session_id = None
142
+ st.session_state.summary = None
143
+ st.session_state.current_question = ""
144
+ st.rerun()
145
  else:
146
  if st.session_state.get("current_question"):
147
  if st.session_state.get("feedback"):
 
151
  st.info(transition_msg)
152
  time.sleep(1)
153
  st.subheader(f"Question {st.session_state.question_number}: {st.session_state.current_question}")
 
154
  is_address_question = st.session_state.current_question == "What is your address?"
155
  is_phone_question = st.session_state.current_question == "What is your phone number?"
 
156
  if is_address_question or is_phone_question:
157
  st.info(
158
  f"This question is optional. Check the box to skip, or enter your information below.\n"
159
  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"
160
  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). Avoid +44 formats."
161
  )
162
+ if is_address_question:
163
+ st.session_state.skip_address = st.checkbox("Skip this question", value=st.session_state.skip_address, key=f"skip_addr_{st.session_state.question_number}")
164
+ elif is_phone_question:
165
+ st.session_state.skip_phone = st.checkbox("Skip this question", value=st.session_state.skip_phone, key=f"skip_phone_{st.session_state.question_number}")
 
166
  st.components.v1.html("""
167
+ document.addEventListener('keypress', function(e) {
168
+ if (e.key === 'Enter' && document.activeElement.tagName === 'INPUT') {
169
+ e.preventDefault();
170
+ const submitButton = document.querySelector('button[key="submit_button_' + window.st.session_state.question_number + '"]');
171
+ if (submitButton && !submitButton.disabled) submitButton.click();
172
+ }
173
+ });
174
  """, height=0)
 
175
  st.session_state.answer = st.text_input("Your Answer", value="", key=f"answer_input_{st.session_state.question_number}")
176
+ if st.button("Submit", key=f"submit_button_{st.session_state.question_number}"):
 
177
  submit_response()
178
  else:
179
  print("Waiting for session to initialize...")
180
 
181
  if __name__ == "__main__":
182
+ # Initialize session state (correctly)
183
+ if "session_id" not in st.session_state:
 
184
  st.session_state.session_id = None
185
  st.session_state.current_question = ""
186
  st.session_state.answer = ""
 
190
  st.session_state.skip_phone = False
191
  st.session_state.prev_question = ""
192
  st.session_state.question_number = 1
 
 
193
  start_registration()
194
+ main()