Upload 2 files
Browse files
index.py
CHANGED
@@ -5,7 +5,6 @@ import time
|
|
5 |
import random
|
6 |
import os
|
7 |
|
8 |
-
# --- CONFIGURATION ---
|
9 |
API_URL = os.getenv("API_URL")
|
10 |
|
11 |
TRANSITION_MESSAGES = [
|
@@ -17,18 +16,22 @@ TRANSITION_MESSAGES = [
|
|
17 |
]
|
18 |
|
19 |
TAB1_FILE = "tab1.txt"
|
|
|
|
|
20 |
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
def read_content_from_file(file_path):
|
24 |
try:
|
25 |
with open(file_path, 'r') as file:
|
26 |
return file.read()
|
27 |
except FileNotFoundError:
|
28 |
-
return
|
29 |
|
30 |
def reset_registration_state():
|
31 |
-
# Remove all registration-related session state keys
|
32 |
for key in [
|
33 |
"session_id", "current_question", "answer", "feedback", "summary",
|
34 |
"skip_address", "skip_phone", "prev_question", "question_number",
|
@@ -89,7 +92,7 @@ def submit_response():
|
|
89 |
st.session_state.answer = ""
|
90 |
st.session_state.skip_address = False
|
91 |
st.session_state.skip_phone = False
|
92 |
-
st.
|
93 |
except requests.RequestException as e:
|
94 |
st.error(f"Error submitting response: {e}")
|
95 |
|
@@ -112,33 +115,26 @@ def edit_field(field, value):
|
|
112 |
st.error(f"Clarification needed for {field}: {data['validation_feedback']}")
|
113 |
elif data.get("message") == "Field updated successfully!":
|
114 |
st.success("Database updated.")
|
115 |
-
st.
|
116 |
except requests.RequestException as e:
|
117 |
st.error(f"Error editing field: {e}")
|
118 |
|
119 |
def ensure_registration_state():
|
120 |
-
# Initialize session state if not already present
|
121 |
if "session_id" not in st.session_state:
|
122 |
start_registration()
|
123 |
if "edit_field_values" not in st.session_state:
|
124 |
st.session_state.edit_field_values = {}
|
125 |
|
126 |
-
# --- MAIN APP LOGIC ---
|
127 |
-
|
128 |
def run_registration_app():
|
129 |
ensure_registration_state()
|
130 |
-
|
131 |
st.title("AI-Powered Registration System")
|
132 |
st.markdown("*** If 403 or other connection errors, please refresh the page every 1 minute, because the backend server is being spun up. Developed by [email protected]**")
|
133 |
|
134 |
-
# --- REGISTRATION COMPLETE ---
|
135 |
if st.session_state.summary:
|
136 |
st.success("Registration Complete!")
|
137 |
st.subheader("Summary")
|
138 |
for key, value in st.session_state.summary.items():
|
139 |
-
# Use a unique key for each edit field
|
140 |
edit_key = f"edit_{key}"
|
141 |
-
# Use session state to persist edit field values
|
142 |
if edit_key not in st.session_state.edit_field_values:
|
143 |
st.session_state.edit_field_values[edit_key] = ""
|
144 |
st.write(f"**{key}**: {value}")
|
@@ -153,15 +149,13 @@ def run_registration_app():
|
|
153 |
col1, col2 = st.columns(2)
|
154 |
with col1:
|
155 |
if st.button("Next Registration", key="next_reg"):
|
156 |
-
# Reset registration and rerun
|
157 |
start_registration()
|
158 |
-
st.
|
159 |
with col2:
|
160 |
if st.button("End Session", key="end_sess"):
|
161 |
reset_registration_state()
|
162 |
st.success("Session ended. Please select 'Registration' tab to start again.")
|
163 |
|
164 |
-
# --- REGISTRATION IN PROGRESS ---
|
165 |
elif st.session_state.current_question:
|
166 |
if st.session_state.feedback and st.session_state.feedback != "Registration complete!":
|
167 |
st.error(st.session_state.feedback)
|
@@ -186,7 +180,6 @@ def run_registration_app():
|
|
186 |
elif is_phone_question:
|
187 |
st.session_state.skip_phone = st.checkbox("Skip this question", value=st.session_state.skip_phone, key="skip_phone_checkbox")
|
188 |
|
189 |
-
# Unique key for each question to avoid double entry
|
190 |
answer_key = f"answer_input_q{st.session_state.question_number}"
|
191 |
st.session_state.answer = st.text_input(
|
192 |
"Your Answer",
|
@@ -200,8 +193,6 @@ def run_registration_app():
|
|
200 |
else:
|
201 |
st.info("Initializing registration session...")
|
202 |
|
203 |
-
# --- STREAMLIT TABS ---
|
204 |
-
|
205 |
tab1, tab2 = st.tabs(["Intro", "Registration"])
|
206 |
|
207 |
with tab1:
|
|
|
5 |
import random
|
6 |
import os
|
7 |
|
|
|
8 |
API_URL = os.getenv("API_URL")
|
9 |
|
10 |
TRANSITION_MESSAGES = [
|
|
|
16 |
]
|
17 |
|
18 |
TAB1_FILE = "tab1.txt"
|
19 |
+
TAB1_FALLBACK = """
|
20 |
+
# Registration System Demo
|
21 |
|
22 |
+
Data quality issues have long plagued council databases, burdening W2 workflow teams (e.g. the Assisted Travel Team's dashboard I am working on), data analysts, and engineers with manual cleaning and validation. This pilot explores how AI-driven workflows can address these pain points by streamlining user registration, ensuring accurate data collection, and reducing validation overhead.
|
23 |
+
|
24 |
+
*If you see this message, `tab1.txt` was not found. Please upload it to the app directory for the full intro page.*
|
25 |
+
"""
|
26 |
|
27 |
def read_content_from_file(file_path):
|
28 |
try:
|
29 |
with open(file_path, 'r') as file:
|
30 |
return file.read()
|
31 |
except FileNotFoundError:
|
32 |
+
return TAB1_FALLBACK
|
33 |
|
34 |
def reset_registration_state():
|
|
|
35 |
for key in [
|
36 |
"session_id", "current_question", "answer", "feedback", "summary",
|
37 |
"skip_address", "skip_phone", "prev_question", "question_number",
|
|
|
92 |
st.session_state.answer = ""
|
93 |
st.session_state.skip_address = False
|
94 |
st.session_state.skip_phone = False
|
95 |
+
st.rerun()
|
96 |
except requests.RequestException as e:
|
97 |
st.error(f"Error submitting response: {e}")
|
98 |
|
|
|
115 |
st.error(f"Clarification needed for {field}: {data['validation_feedback']}")
|
116 |
elif data.get("message") == "Field updated successfully!":
|
117 |
st.success("Database updated.")
|
118 |
+
st.rerun()
|
119 |
except requests.RequestException as e:
|
120 |
st.error(f"Error editing field: {e}")
|
121 |
|
122 |
def ensure_registration_state():
|
|
|
123 |
if "session_id" not in st.session_state:
|
124 |
start_registration()
|
125 |
if "edit_field_values" not in st.session_state:
|
126 |
st.session_state.edit_field_values = {}
|
127 |
|
|
|
|
|
128 |
def run_registration_app():
|
129 |
ensure_registration_state()
|
|
|
130 |
st.title("AI-Powered Registration System")
|
131 |
st.markdown("*** If 403 or other connection errors, please refresh the page every 1 minute, because the backend server is being spun up. Developed by [email protected]**")
|
132 |
|
|
|
133 |
if st.session_state.summary:
|
134 |
st.success("Registration Complete!")
|
135 |
st.subheader("Summary")
|
136 |
for key, value in st.session_state.summary.items():
|
|
|
137 |
edit_key = f"edit_{key}"
|
|
|
138 |
if edit_key not in st.session_state.edit_field_values:
|
139 |
st.session_state.edit_field_values[edit_key] = ""
|
140 |
st.write(f"**{key}**: {value}")
|
|
|
149 |
col1, col2 = st.columns(2)
|
150 |
with col1:
|
151 |
if st.button("Next Registration", key="next_reg"):
|
|
|
152 |
start_registration()
|
153 |
+
st.rerun()
|
154 |
with col2:
|
155 |
if st.button("End Session", key="end_sess"):
|
156 |
reset_registration_state()
|
157 |
st.success("Session ended. Please select 'Registration' tab to start again.")
|
158 |
|
|
|
159 |
elif st.session_state.current_question:
|
160 |
if st.session_state.feedback and st.session_state.feedback != "Registration complete!":
|
161 |
st.error(st.session_state.feedback)
|
|
|
180 |
elif is_phone_question:
|
181 |
st.session_state.skip_phone = st.checkbox("Skip this question", value=st.session_state.skip_phone, key="skip_phone_checkbox")
|
182 |
|
|
|
183 |
answer_key = f"answer_input_q{st.session_state.question_number}"
|
184 |
st.session_state.answer = st.text_input(
|
185 |
"Your Answer",
|
|
|
193 |
else:
|
194 |
st.info("Initializing registration session...")
|
195 |
|
|
|
|
|
196 |
tab1, tab2 = st.tabs(["Intro", "Registration"])
|
197 |
|
198 |
with tab1:
|
tab1.txt
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
Data quality issues have long plagued council databases, burdening W2 workflow teams (e.g. the Assisted Travel Team's dashboard I am working on), data analysts, and engineers with manual cleaning and validation. This pilot explores how AI-driven workflows can address these pain points by streamlining user registration, ensuring accurate data collection, and reducing validation overhead.
|
2 |
|
3 |
-
* If 403 or other connection errors, it is because the backend server is being spinned up. Please stay patient and try refresh the page every 1 minute. It takes 1-3mins to spin up usually. 2mins is the average; but could take 5mins or more.
|
4 |
|
5 |
### What is this Registration System?
|
6 |
This application leverages **FastAPI**, **LangGraph**, and **AI validation** (**ChatGPT** with **Guardrails AI** and **dspy**) to collect user information (email, name, address, phone, username, password (included only a few for demo purpose)) with optional fields and real-time validation. It uses real-time validation to enforce formats (e.g., addresses, phone numbers), minimizing errors and enhancing data integrity stored in a PostgreSQL database.
|
|
|
1 |
Data quality issues have long plagued council databases, burdening W2 workflow teams (e.g. the Assisted Travel Team's dashboard I am working on), data analysts, and engineers with manual cleaning and validation. This pilot explores how AI-driven workflows can address these pain points by streamlining user registration, ensuring accurate data collection, and reducing validation overhead.
|
2 |
|
|
|
3 |
|
4 |
### What is this Registration System?
|
5 |
This application leverages **FastAPI**, **LangGraph**, and **AI validation** (**ChatGPT** with **Guardrails AI** and **dspy**) to collect user information (email, name, address, phone, username, password (included only a few for demo purpose)) with optional fields and real-time validation. It uses real-time validation to enforce formats (e.g., addresses, phone numbers), minimizing errors and enhancing data integrity stored in a PostgreSQL database.
|