Upload 3 files
Browse files
index.py
CHANGED
@@ -24,6 +24,18 @@ TRANSITION_MESSAGES = [
|
|
24 |
"Onward to question {number}!"
|
25 |
]
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def start_registration():
|
28 |
print("Starting registration...")
|
29 |
try:
|
@@ -31,16 +43,9 @@ def start_registration():
|
|
31 |
response.raise_for_status()
|
32 |
data = response.json()
|
33 |
print("API Response:", data)
|
34 |
-
# Reset session state for new registration
|
35 |
st.session_state.session_id = data["session_id"]
|
36 |
st.session_state.current_question = data["message"]
|
37 |
-
st.session_state.
|
38 |
-
st.session_state.summary = None
|
39 |
-
st.session_state.answer = ""
|
40 |
-
st.session_state.skip_address = False
|
41 |
-
st.session_state.skip_phone = False
|
42 |
-
st.session_state.prev_question = ""
|
43 |
-
st.session_state.question_number = 1
|
44 |
except requests.RequestException as e:
|
45 |
print(f"Error starting registration: {e}")
|
46 |
st.error(f"Error starting registration: {e}")
|
@@ -69,7 +74,7 @@ def submit_response():
|
|
69 |
st.session_state.summary = data["summary"]
|
70 |
st.session_state.current_question = ""
|
71 |
st.session_state.feedback = "Registration complete!"
|
72 |
-
st.session_state.question_number = 1
|
73 |
else:
|
74 |
st.session_state.prev_question = st.session_state.current_question
|
75 |
st.session_state.current_question = data.get("next_question", "")
|
@@ -134,15 +139,15 @@ def main():
|
|
134 |
st.subheader("Summary")
|
135 |
for key, value in st.session_state.summary.items():
|
136 |
st.write(f"**{key}**: {value}")
|
137 |
-
new_value = st.text_input(f"Edit {key}", key=f"edit_{key}")
|
138 |
-
if st.button(f"Update {key}", key=f"update_{key}"):
|
139 |
edit_field(key, new_value)
|
140 |
col1, col2 = st.columns(2)
|
141 |
with col1:
|
142 |
-
if st.button("Next Registration", key="next_reg", on_click=lambda: (start_registration(), st.rerun())):
|
143 |
pass
|
144 |
with col2:
|
145 |
-
if st.button("End Session", key="end_sess", on_click=lambda: (start_registration(), st.rerun())):
|
146 |
pass
|
147 |
else:
|
148 |
if st.session_state.get("current_question"):
|
@@ -164,9 +169,9 @@ def main():
|
|
164 |
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."
|
165 |
)
|
166 |
if is_address_question:
|
167 |
-
st.session_state.skip_address = st.checkbox("Skip this question", value=st.session_state.skip_address)
|
168 |
elif is_phone_question:
|
169 |
-
st.session_state.skip_phone = st.checkbox("Skip this question", value=st.session_state.skip_phone)
|
170 |
|
171 |
st.components.v1.html("""
|
172 |
document.addEventListener('keypress', function(e) {
|
@@ -178,7 +183,7 @@ def main():
|
|
178 |
});
|
179 |
""", height=0)
|
180 |
|
181 |
-
st.session_state.answer = st.text_input("Your Answer", value="", key=f"answer_input_{st.session_state.question_number}")
|
182 |
|
183 |
if st.button("Submit", key="submit_button"):
|
184 |
submit_response()
|
@@ -189,15 +194,7 @@ if __name__ == "__main__":
|
|
189 |
# Initialize session state
|
190 |
if "session_state" not in st.session_state:
|
191 |
st.session_state.session_state = {}
|
192 |
-
|
193 |
-
st.session_state.current_question = ""
|
194 |
-
st.session_state.answer = ""
|
195 |
-
st.session_state.feedback = ""
|
196 |
-
st.session_state.summary = None
|
197 |
-
st.session_state.skip_address = False
|
198 |
-
st.session_state.skip_phone = False
|
199 |
-
st.session_state.prev_question = ""
|
200 |
-
st.session_state.question_number = 1
|
201 |
|
202 |
if st.session_state.session_id is None:
|
203 |
start_registration()
|
|
|
24 |
"Onward to question {number}!"
|
25 |
]
|
26 |
|
27 |
+
def reset_session_state():
|
28 |
+
"""Reset session state to start a new registration."""
|
29 |
+
st.session_state.session_id = None
|
30 |
+
st.session_state.current_question = ""
|
31 |
+
st.session_state.feedback = ""
|
32 |
+
st.session_state.summary = None
|
33 |
+
st.session_state.answer = ""
|
34 |
+
st.session_state.skip_address = False
|
35 |
+
st.session_state.skip_phone = False
|
36 |
+
st.session_state.prev_question = ""
|
37 |
+
st.session_state.question_number = 1
|
38 |
+
|
39 |
def start_registration():
|
40 |
print("Starting registration...")
|
41 |
try:
|
|
|
43 |
response.raise_for_status()
|
44 |
data = response.json()
|
45 |
print("API Response:", data)
|
|
|
46 |
st.session_state.session_id = data["session_id"]
|
47 |
st.session_state.current_question = data["message"]
|
48 |
+
st.session_state.question_number = 1 # Reset question number for new session
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
except requests.RequestException as e:
|
50 |
print(f"Error starting registration: {e}")
|
51 |
st.error(f"Error starting registration: {e}")
|
|
|
74 |
st.session_state.summary = data["summary"]
|
75 |
st.session_state.current_question = ""
|
76 |
st.session_state.feedback = "Registration complete!"
|
77 |
+
st.session_state.question_number = 1 # Reset for potential next session
|
78 |
else:
|
79 |
st.session_state.prev_question = st.session_state.current_question
|
80 |
st.session_state.current_question = data.get("next_question", "")
|
|
|
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}_{st.session_state.session_id}") # Unique key per session
|
143 |
+
if st.button(f"Update {key}", key=f"update_{key}_{st.session_state.session_id}"):
|
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=lambda: (reset_session_state(), start_registration(), st.rerun())):
|
148 |
pass
|
149 |
with col2:
|
150 |
+
if st.button("End Session", key="end_sess", on_click=lambda: (reset_session_state(), start_registration(), st.rerun())):
|
151 |
pass
|
152 |
else:
|
153 |
if st.session_state.get("current_question"):
|
|
|
169 |
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."
|
170 |
)
|
171 |
if is_address_question:
|
172 |
+
st.session_state.skip_address = st.checkbox("Skip this question", key=f"skip_address_{st.session_state.session_id}", value=st.session_state.skip_address)
|
173 |
elif is_phone_question:
|
174 |
+
st.session_state.skip_phone = st.checkbox("Skip this question", key=f"skip_phone_{st.session_state.session_id}", value=st.session_state.skip_phone)
|
175 |
|
176 |
st.components.v1.html("""
|
177 |
document.addEventListener('keypress', function(e) {
|
|
|
183 |
});
|
184 |
""", height=0)
|
185 |
|
186 |
+
st.session_state.answer = st.text_input("Your Answer", value="", key=f"answer_input_{st.session_state.question_number}_{st.session_state.session_id}") # Unique key per question and session
|
187 |
|
188 |
if st.button("Submit", key="submit_button"):
|
189 |
submit_response()
|
|
|
194 |
# Initialize session state
|
195 |
if "session_state" not in st.session_state:
|
196 |
st.session_state.session_state = {}
|
197 |
+
reset_session_state()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
if st.session_state.session_id is None:
|
200 |
start_registration()
|
tab1.txt
CHANGED
@@ -1,9 +1,6 @@
|
|
1 |
-
# Welcome to the AI-Powered Registration System prototype!
|
2 |
-
|
3 |
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.
|
4 |
|
5 |
-
|
6 |
-
## What is the Registration System?
|
7 |
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.
|
8 |
|
9 |
## How Does It Work?
|
@@ -17,7 +14,7 @@ This application leverages **FastAPI**, **LangGraph**, and **AI validation** (**
|
|
17 |
- Explore **scalable**, secure registration systems for public sector applications. The Same logic could apply to Copilot's Agent, and Power Apps.
|
18 |
|
19 |
## Prototype
|
20 |
-
We encourage you to test the system with varied inputs to evaluate its robustness.
|
21 |
|
22 |
**Last Update**: 30th June 2025
|
23 |
|
|
|
|
|
|
|
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 |
+
## What is this Registration System?
|
|
|
4 |
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.
|
5 |
|
6 |
## How Does It Work?
|
|
|
14 |
- Explore **scalable**, secure registration systems for public sector applications. The Same logic could apply to Copilot's Agent, and Power Apps.
|
15 |
|
16 |
## Prototype
|
17 |
+
We encourage you to test the system with varied inputs to evaluate its robustness. You will see the input summary in the end of registration. You will be amazed how the system would prompt you for the better answer if too ambiguous, and how capable it is in standardising and cleaning up the data.
|
18 |
|
19 |
**Last Update**: 30th June 2025
|
20 |
|
tab2.txt
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 | |
2 | |
3 |
+
The email address appears to have a typo in the domain extension:
|
4 |
+
'yahoo.come.uk' is not a valid domain. Please check and provide a correct email address.
|
5 |
|
6 |
+
michael jordan (double spaces)
|
7 |
+
Name formatted correctly with capitalization.
|
8 |
|
9 |
+
r2 123 High Street, London, SW1A 1AA.
|
10 |
+
The address includes a room identifier, house number, street name, city, and postcode, meeting the required format.
|
11 |
+
Room 2, 123 High Street, London, SW1A 1AA
|
12 |
+
|
13 |
+
+4407442757070
|
14 |
+
The phone number is a valid UK mobile number in international format and has been correctly converted to national format.
|
15 |
+
07442 757 070
|