nagur-shareef-shaik commited on
Commit
0756e8b
·
1 Parent(s): 48e2f91

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -49
app.py CHANGED
@@ -49,7 +49,7 @@ if "thread_id" not in st.session_state:
49
  st.session_state.user_profile = {}
50
  st.session_state.chat_history = []
51
  st.session_state.is_profile_complete = False
52
- st.session_state.phase = "zip"
53
 
54
  # --- Helper Functions for API Calls ---
55
  def get_geodata(_zip_code: str):
@@ -85,53 +85,47 @@ def send_chat_message_to_backend(user_message: str):
85
  st.error(f"Error communicating with the AI service: {e}")
86
 
87
  # --- UI Rendering Functions ---
88
- def display_zip_form():
89
- st.header("Let's Start with Your Location")
90
  zip_code_input = st.text_input("Enter your 5-digit ZIP code:", max_chars=5)
91
- if st.button("Confirm ZIP Code"):
92
- if zip_code_input and len(zip_code_input) == 5 and zip_code_input.isdigit():
93
- with st.spinner("Verifying ZIP code..."):
94
- geo_data = get_geodata(zip_code_input)
95
- if geo_data:
96
- st.session_state.user_profile.update(geo_data)
97
- st.session_state.phase = "basic_profile"
98
- st.rerun()
99
- else:
100
- st.error("Invalid ZIP code or could not retrieve location data.")
101
- else:
102
- st.error("Please enter a valid 5-digit ZIP code.")
103
 
104
- def display_basic_profile_form():
105
- st.header("Tell Us More About You")
106
- st.write(f"**Location:** {st.session_state.user_profile.get('city', '')}, {st.session_state.user_profile.get('state', '')}")
107
-
108
- with st.form("basic_profile_form"):
109
- st.subheader("Please provide some basic information:")
110
-
111
- age = st.number_input("Your Age", min_value=1, max_value=120, value=None, placeholder="Enter your age")
112
- gender = st.selectbox("Your Gender", [None, "Male", "Female", "Non-binary", "Prefer not to say"], index=0, format_func=lambda x: "Select an option" if x is None else x)
113
- household_size = st.number_input("Household Size (including yourself)", min_value=1, value=None, placeholder="e.g., 1")
114
- income = st.number_input("Estimated Annual Household Income ($)", min_value=0, step=1000, value=None, placeholder="e.g., 55000")
115
- employment_status = st.selectbox("Your Employment Status", [None, "Employed with employer coverage", "Employed without coverage", "Unemployed", "Retired", "Student", "Self-employed"], index=0, format_func=lambda x: "Select an option" if x is None else x)
116
- citizenship = st.selectbox("Your Citizenship Status", [None, "US Citizen", "Lawful Permanent Resident", "Other legal resident", "Non-resident"], index=0, format_func=lambda x: "Select an option" if x is None else x)
117
-
118
- submitted = st.form_submit_button("Start My Personalized Session")
119
-
120
- if submitted:
121
- if not all([age, gender, household_size, income is not None, employment_status, citizenship]):
122
- st.error("Please fill out all the fields to continue.")
123
 
124
- else:
125
- st.session_state.user_profile.update({
126
- "age": age, "gender": gender, "household_size": household_size,
127
- "income": income, "employment_status": employment_status,
128
- "citizenship": citizenship,
129
- "medical_history": None, "medications": None, "special_cases": None
130
- })
131
- st.session_state.phase = "chat"
132
- with st.spinner("Starting your personalized profile conversation..."):
133
- send_chat_message_to_backend("START_PROFILE_BUILDING")
134
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  def display_chat_interface():
137
  # Display chat history from session state
@@ -149,10 +143,9 @@ def display_chat_interface():
149
  st.rerun()
150
 
151
  # --- Main Application Flow Control ---
152
- if st.session_state.phase == "zip":
153
- display_zip_form()
154
- elif st.session_state.phase == "basic_profile":
155
- display_basic_profile_form()
156
  else: # 'chat' phase
157
  display_chat_interface()
158
 
 
49
  st.session_state.user_profile = {}
50
  st.session_state.chat_history = []
51
  st.session_state.is_profile_complete = False
52
+ st.session_state.phase = "user-profiling"
53
 
54
  # --- Helper Functions for API Calls ---
55
  def get_geodata(_zip_code: str):
 
85
  st.error(f"Error communicating with the AI service: {e}")
86
 
87
  # --- UI Rendering Functions ---
88
+ def display_form_interface():
 
89
  zip_code_input = st.text_input("Enter your 5-digit ZIP code:", max_chars=5)
90
+ if zip_code_input and len(zip_code_input) == 5 and zip_code_input.isdigit():
91
+ with st.spinner("Verifying ZIP code..."):
92
+ geo_data = get_geodata(zip_code_input)
93
+ if geo_data:
94
+ st.session_state.user_profile.update(geo_data)
 
 
 
 
 
 
 
95
 
96
+ st.write(f"**Location:** {st.session_state.user_profile.get('county', '')} County, {st.session_state.user_profile.get('city', '')}, {st.session_state.user_profile.get('state', '')}")
97
+
98
+ with st.form("user_profile_form"):
99
+
100
+ age = st.number_input("Your Age", min_value=1, max_value=120, value=None, placeholder="Enter your age")
101
+ gender = st.selectbox("Your Gender", [None, "Male", "Female", "Non-binary", "Prefer not to say"], index=0, format_func=lambda x: "Select an option" if x is None else x)
102
+ household_size = st.number_input("Household Size (including yourself)", min_value=1, value=None, placeholder="e.g., 1")
103
+ income = st.number_input("Estimated Annual Household Income ($)", min_value=0, step=1000, value=None, placeholder="e.g., 55000")
104
+ employment_status = st.selectbox("Your Employment Status", [None, "Employed with employer coverage", "Employed without coverage", "Unemployed", "Retired", "Student", "Self-employed"], index=0, format_func=lambda x: "Select an option" if x is None else x)
105
+ citizenship = st.selectbox("Your Citizenship Status", [None, "US Citizen", "Lawful Permanent Resident", "Other legal resident", "Non-resident"], index=0, format_func=lambda x: "Select an option" if x is None else x)
 
 
 
 
 
 
 
 
 
106
 
107
+ submitted = st.form_submit_button("Start My Personalized Session")
108
+
109
+ if submitted:
110
+ if not all([age, gender, household_size, income is not None, employment_status, citizenship]):
111
+ st.error("Please fill out all the fields to continue.")
112
+
113
+ else:
114
+ st.session_state.user_profile.update({
115
+ "age": age, "gender": gender, "household_size": household_size,
116
+ "income": income, "employment_status": employment_status,
117
+ "citizenship": citizenship,
118
+ "medical_history": None, "medications": None, "special_cases": None
119
+ })
120
+ st.session_state.phase = "chat"
121
+ with st.spinner("Starting your personalized profile conversation..."):
122
+ send_chat_message_to_backend("START_PROFILE_BUILDING")
123
+ st.rerun()
124
+
125
+ else:
126
+ st.error("Invalid ZIP code or could not retrieve location data.")
127
+ else:
128
+ st.info("Please enter a valid 5-digit ZIP code.")
129
 
130
  def display_chat_interface():
131
  # Display chat history from session state
 
143
  st.rerun()
144
 
145
  # --- Main Application Flow Control ---
146
+ if st.session_state.phase == "user-profiling":
147
+ display_form_interface()
148
+
 
149
  else: # 'chat' phase
150
  display_chat_interface()
151