Upload 3 files
Browse files
index.py
CHANGED
@@ -6,8 +6,7 @@ import random
|
|
6 |
import os
|
7 |
|
8 |
# Load environment variables
|
9 |
-
|
10 |
-
API_URL = os.getenv("API_URL")
|
11 |
|
12 |
# Read content from text files
|
13 |
def read_content_from_file(file_path):
|
@@ -27,23 +26,32 @@ TRANSITION_MESSAGES = [
|
|
27 |
|
28 |
def start_registration():
|
29 |
print("Starting registration...")
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
def submit_response():
|
49 |
if not st.session_state.session_id:
|
@@ -105,7 +113,7 @@ def edit_field(field, value):
|
|
105 |
st.error(f"Clarification needed for {field}: {data['validation_feedback']}")
|
106 |
elif data.get("message") == "Field updated successfully!":
|
107 |
st.success("Database updated.")
|
108 |
-
st.
|
109 |
except requests.RequestException as e:
|
110 |
print(f"Error editing field: {e}")
|
111 |
st.error(f"Error editing field: {e}")
|
@@ -139,11 +147,13 @@ def main():
|
|
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=start_registration):
|
143 |
-
|
|
|
144 |
with col2:
|
145 |
-
if st.button("End Session", key="end_sess", on_click=start_registration):
|
146 |
-
|
|
|
147 |
else:
|
148 |
if st.session_state.get("current_question"):
|
149 |
if st.session_state.get("feedback"):
|
@@ -198,6 +208,7 @@ if __name__ == "__main__":
|
|
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()
|
|
|
6 |
import os
|
7 |
|
8 |
# Load environment variables
|
9 |
+
API_URL = os.getenv("API_URL", "https://registration-backend-r1uy.onrender.com")
|
|
|
10 |
|
11 |
# Read content from text files
|
12 |
def read_content_from_file(file_path):
|
|
|
26 |
|
27 |
def start_registration():
|
28 |
print("Starting registration...")
|
29 |
+
if "backend_waiting" not in st.session_state:
|
30 |
+
st.session_state.backend_waiting = False
|
31 |
+
if not st.session_state.backend_waiting:
|
32 |
+
st.session_state.backend_waiting = True
|
33 |
+
st.warning("Waiting up to 2 minutes for the backend to spin up. Please wait...")
|
34 |
+
try:
|
35 |
+
response = requests.post(f"{API_URL}/start_registration", timeout=120)
|
36 |
+
response.raise_for_status()
|
37 |
+
data = response.json()
|
38 |
+
print("API Response:", data)
|
39 |
+
st.session_state.session_id = data["session_id"]
|
40 |
+
st.session_state.current_question = data["message"]
|
41 |
+
st.session_state.feedback = ""
|
42 |
+
st.session_state.summary = None
|
43 |
+
st.session_state.answer = ""
|
44 |
+
st.session_state.skip_address = False
|
45 |
+
st.session_state.skip_phone = False
|
46 |
+
st.session_state.prev_question = ""
|
47 |
+
st.session_state.question_number = 1
|
48 |
+
st.session_state.backend_waiting = False
|
49 |
+
except requests.RequestException as e:
|
50 |
+
print(f"Error starting registration: {e}")
|
51 |
+
st.error(f"Error starting registration: {e}")
|
52 |
+
st.session_state.backend_waiting = False
|
53 |
+
else:
|
54 |
+
st.warning("Backend is still waking up. Please wait...")
|
55 |
|
56 |
def submit_response():
|
57 |
if not st.session_state.session_id:
|
|
|
113 |
st.error(f"Clarification needed for {field}: {data['validation_feedback']}")
|
114 |
elif data.get("message") == "Field updated successfully!":
|
115 |
st.success("Database updated.")
|
116 |
+
st.run()
|
117 |
except requests.RequestException as e:
|
118 |
print(f"Error editing field: {e}")
|
119 |
st.error(f"Error editing field: {e}")
|
|
|
147 |
edit_field(key, new_value)
|
148 |
col1, col2 = st.columns(2)
|
149 |
with col1:
|
150 |
+
if st.button("Next Registration", key="next_reg", on_click=lambda: start_registration()):
|
151 |
+
st.session_state.session_id = None
|
152 |
+
st.rerun()
|
153 |
with col2:
|
154 |
+
if st.button("End Session", key="end_sess", on_click=lambda: start_registration()):
|
155 |
+
st.session_state.session_id = None
|
156 |
+
st.rerun()
|
157 |
else:
|
158 |
if st.session_state.get("current_question"):
|
159 |
if st.session_state.get("feedback"):
|
|
|
208 |
st.session_state.skip_phone = False
|
209 |
st.session_state.prev_question = ""
|
210 |
st.session_state.question_number = 1
|
211 |
+
st.session_state.backend_waiting = False
|
212 |
|
213 |
if st.session_state.session_id is None:
|
214 |
start_registration()
|
tab1.txt
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
-
# Welcome to the AI-Powered Registration System
|
2 |
|
3 |
-
|
4 |
|
5 |
-
This initiative explores the capabilities of AI-driven workflows to streamline user registration, focusing on efficient data collection and validation. The system uses a stateful LangGraph workflow to guide users through a dynamic registration process, inspired by modern conversational interfaces.
|
6 |
|
7 |
## What is the Registration System?
|
8 |
-
This application leverages FastAPI
|
9 |
|
10 |
## How Does It Work?
|
11 |
- **Register**: In the "Registration" tab, users answer a series of questions, with optional fields (address, phone) skippable.
|
12 |
-
- **Validation**: AI validates inputs (e.g.,
|
13 |
-
- **Data Storage**: Responses are saved securely in a database for review and editing.
|
14 |
|
15 |
## Objectives
|
16 |
-
-
|
17 |
-
- Enhance efficiency in user onboarding processes.
|
18 |
-
- Explore scalable
|
19 |
|
20 |
-
##
|
21 |
-
We encourage
|
22 |
|
23 |
**Last Update**: 30th June 2025
|
24 |
|
25 |
-
**By Lorentz Yeung, Data Scientist**
|
|
|
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?
|
10 |
- **Register**: In the "Registration" tab, users answer a series of questions, with optional fields (address, phone) skippable.
|
11 |
+
- **Validation**: AI validates inputs (e.g., e.g. address formats, phone numbers, will ask for clarification if ambiguous).
|
12 |
+
- **Data Storage**: Responses are saved securely in a database for review and editing (currently in a PostgreSQL db in another server.).
|
13 |
|
14 |
## Objectives
|
15 |
+
- Address **data quality** issues by automating validation and reducing errors.
|
16 |
+
- Enhance **efficiency** in user onboarding processes.
|
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. Your feedback is vital for improving this pilot.
|
21 |
|
22 |
**Last Update**: 30th June 2025
|
23 |
|
24 |
+
**By Lorentz Yeung, AI Engineer & Data Scientist**
|
tab2.txt
CHANGED
@@ -1,13 +1,8 @@
|
|
1 |
-
## Registration Process
|
2 |
-
|
3 |
-
This tab guides you through a streamlined registration process. You'll be asked a series of questions to collect your information, including email, name, address, phone, username, and password. The address and phone questions are optional and can be skipped.
|
4 |
-
|
5 |
### How to Use
|
6 |
- Answer each question in the provided text box.
|
7 |
-
-
|
8 |
-
-
|
9 |
-
|
10 |
-
- **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.
|
11 |
- After completing all questions, review your data in the summary and edit if needed.
|
12 |
- Use "Next Registration" to start a new session or "End Session" to reset.
|
13 |
|
|
|
|
|
|
|
|
|
|
|
1 |
### How to Use
|
2 |
- Answer each question in the provided text box.
|
3 |
+
- Check the "Skip this question" box if you prefer not to provide the information.
|
4 |
+
-
|
5 |
+
|
|
|
6 |
- After completing all questions, review your data in the summary and edit if needed.
|
7 |
- Use "Next Registration" to start a new session or "End Session" to reset.
|
8 |
|