Upload index.py
Browse files
index.py
CHANGED
|
@@ -26,43 +26,23 @@ TRANSITION_MESSAGES = [
|
|
| 26 |
|
| 27 |
def start_registration():
|
| 28 |
print("Starting registration...")
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
st.session_state.skip_phone = False
|
| 47 |
-
st.session_state.prev_question = ""
|
| 48 |
-
st.session_state.question_number = 1
|
| 49 |
-
st.session_state.backend_waiting = False
|
| 50 |
-
st.experimental_rerun() # Refresh to clear the warning
|
| 51 |
-
except requests.exceptions.HTTPError as e:
|
| 52 |
-
if e.response.status_code == 403:
|
| 53 |
-
st.session_state.backend_waiting = False
|
| 54 |
-
st.error("Backend unavailable, please try again later.")
|
| 55 |
-
else:
|
| 56 |
-
st.session_state.backend_waiting = False
|
| 57 |
-
st.error(f"Unexpected error: {e}")
|
| 58 |
-
except requests.RequestException as e:
|
| 59 |
-
st.session_state.backend_waiting = False
|
| 60 |
-
st.error("Connection issue, please try again later.")
|
| 61 |
-
else:
|
| 62 |
-
st.warning("Backend is still waking up. Please wait...")
|
| 63 |
-
else:
|
| 64 |
-
# Backend is already spun up, no need to show waiting message
|
| 65 |
-
pass
|
| 66 |
|
| 67 |
def submit_response():
|
| 68 |
if not st.session_state.session_id:
|
|
@@ -84,7 +64,7 @@ def submit_response():
|
|
| 84 |
response.raise_for_status()
|
| 85 |
data = response.json()
|
| 86 |
print("API Response:", data)
|
| 87 |
-
if data.get("message") == "Registration complete!":
|
| 88 |
st.session_state.summary = data["summary"]
|
| 89 |
st.session_state.current_question = ""
|
| 90 |
st.session_state.feedback = "Registration complete!"
|
|
@@ -99,13 +79,9 @@ def submit_response():
|
|
| 99 |
st.session_state.skip_address = False
|
| 100 |
st.session_state.skip_phone = False
|
| 101 |
st.rerun()
|
| 102 |
-
except requests.exceptions.HTTPError as e:
|
| 103 |
-
if e.response.status_code == 403:
|
| 104 |
-
st.error("Backend unavailable, please try again later.")
|
| 105 |
-
else:
|
| 106 |
-
st.error(f"Unexpected error: {e}")
|
| 107 |
except requests.RequestException as e:
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
def edit_field(field, value):
|
| 111 |
if not st.session_state.session_id:
|
|
@@ -124,18 +100,14 @@ def edit_field(field, value):
|
|
| 124 |
print("API Response:", data)
|
| 125 |
st.session_state.feedback = data.get("validation_feedback", "")
|
| 126 |
st.session_state.summary = data.get("summary", st.session_state.summary)
|
| 127 |
-
if data.get("message") == "Needs clarification":
|
| 128 |
st.error(f"Clarification needed for {field}: {data['validation_feedback']}")
|
| 129 |
-
elif data.get("message") == "Field updated successfully!":
|
| 130 |
st.success("Database updated.")
|
| 131 |
st.rerun()
|
| 132 |
-
except requests.exceptions.HTTPError as e:
|
| 133 |
-
if e.response.status_code == 403:
|
| 134 |
-
st.error("Backend unavailable, please try again later.")
|
| 135 |
-
else:
|
| 136 |
-
st.error(f"Unexpected error: {e}")
|
| 137 |
except requests.RequestException as e:
|
| 138 |
-
|
|
|
|
| 139 |
|
| 140 |
def main():
|
| 141 |
st.title("AI-Powered Registration System")
|
|
@@ -151,6 +123,7 @@ def main():
|
|
| 151 |
|
| 152 |
# Tab 2: Registration Application
|
| 153 |
with tab2:
|
|
|
|
| 154 |
registration_content = read_content_from_file("tab2.txt")
|
| 155 |
st.markdown(registration_content)
|
| 156 |
st.markdown("**Developed by [email protected]**")
|
|
@@ -165,13 +138,11 @@ def main():
|
|
| 165 |
edit_field(key, new_value)
|
| 166 |
col1, col2 = st.columns(2)
|
| 167 |
with col1:
|
| 168 |
-
if st.button("Next Registration", key="next_reg", on_click=
|
| 169 |
-
|
| 170 |
-
st.rerun()
|
| 171 |
with col2:
|
| 172 |
-
if st.button("End Session", key="end_sess", on_click=
|
| 173 |
-
|
| 174 |
-
st.rerun()
|
| 175 |
else:
|
| 176 |
if st.session_state.get("current_question"):
|
| 177 |
if st.session_state.get("feedback"):
|
|
@@ -211,7 +182,7 @@ def main():
|
|
| 211 |
if st.button("Submit", key="submit_button"):
|
| 212 |
submit_response()
|
| 213 |
else:
|
| 214 |
-
|
| 215 |
|
| 216 |
if __name__ == "__main__":
|
| 217 |
# Initialize session state
|
|
@@ -226,6 +197,8 @@ if __name__ == "__main__":
|
|
| 226 |
st.session_state.skip_phone = False
|
| 227 |
st.session_state.prev_question = ""
|
| 228 |
st.session_state.question_number = 1
|
| 229 |
-
|
|
|
|
|
|
|
| 230 |
|
| 231 |
main()
|
|
|
|
| 26 |
|
| 27 |
def start_registration():
|
| 28 |
print("Starting registration...")
|
| 29 |
+
try:
|
| 30 |
+
response = requests.post(f"{API_URL}/start_registration", timeout=60)
|
| 31 |
+
response.raise_for_status()
|
| 32 |
+
data = response.json()
|
| 33 |
+
print("API Response:", data)
|
| 34 |
+
st.session_state.session_id = data["session_id"]
|
| 35 |
+
st.session_state.current_question = data["message"]
|
| 36 |
+
st.session_state.feedback = ""
|
| 37 |
+
st.session_state.summary = None
|
| 38 |
+
st.session_state.answer = ""
|
| 39 |
+
st.session_state.skip_address = False
|
| 40 |
+
st.session_state.skip_phone = False
|
| 41 |
+
st.session_state.prev_question = ""
|
| 42 |
+
st.session_state.question_number = 1
|
| 43 |
+
except requests.RequestException as e:
|
| 44 |
+
print(f"Error starting registration: {e}")
|
| 45 |
+
st.error(f"Error starting registration: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def submit_response():
|
| 48 |
if not st.session_state.session_id:
|
|
|
|
| 64 |
response.raise_for_status()
|
| 65 |
data = response.json()
|
| 66 |
print("API Response:", data)
|
| 67 |
+
if data.get("message") == "Registration complete!"):
|
| 68 |
st.session_state.summary = data["summary"]
|
| 69 |
st.session_state.current_question = ""
|
| 70 |
st.session_state.feedback = "Registration complete!"
|
|
|
|
| 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}")
|
| 84 |
+
st.error(f"Error submitting response: {e}")
|
| 85 |
|
| 86 |
def edit_field(field, value):
|
| 87 |
if not st.session_state.session_id:
|
|
|
|
| 100 |
print("API Response:", data)
|
| 101 |
st.session_state.feedback = data.get("validation_feedback", "")
|
| 102 |
st.session_state.summary = data.get("summary", st.session_state.summary)
|
| 103 |
+
if data.get("message") == "Needs clarification"):
|
| 104 |
st.error(f"Clarification needed for {field}: {data['validation_feedback']}")
|
| 105 |
+
elif data.get("message") == "Field updated successfully!"):
|
| 106 |
st.success("Database updated.")
|
| 107 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
except requests.RequestException as e:
|
| 109 |
+
print(f"Error editing field: {e}")
|
| 110 |
+
st.error(f"Error editing field: {e}")
|
| 111 |
|
| 112 |
def main():
|
| 113 |
st.title("AI-Powered Registration System")
|
|
|
|
| 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]**")
|
|
|
|
| 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"):
|
|
|
|
| 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
|
|
|
|
| 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()
|