Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -87,39 +87,6 @@ def haversine(lat1, lon1, lat2, lon2):
|
|
87 |
distance = R * c
|
88 |
return distance
|
89 |
|
90 |
-
# # Function to handle form submission
|
91 |
-
# @st.experimental_dialog("Fill out the form")
|
92 |
-
# def form_dialog():
|
93 |
-
# city = st.selectbox("City", ['San Francisco', 'Oakland', 'Berkeley'])
|
94 |
-
# zipcode = st.selectbox("Zipcode")
|
95 |
-
|
96 |
-
# sex = st.radio("Sex", ["Male", "Female", "Other"])
|
97 |
-
# lgbtq = st.radio("Do you identify as LGBTQ+ (some shelters serve this community specifically)", ["No", "Yes"])
|
98 |
-
# domestic_violence = st.radio("Have you experienced domestic violence (some shelters serve these individuals specifically", ["No", "Yes"])
|
99 |
-
|
100 |
-
# urgency = st.radio("How quickly do you need help?", ("Today", "In the next few days", "In a week or more"))
|
101 |
-
# duration = st.radio("How long do you need a place to stay?", ("Overnight", "A month or less", "A couple of months", "A year or more"))
|
102 |
-
# needs = st.text_area("Optional - Needs (tell us what you need and how we can help)")
|
103 |
-
|
104 |
-
# if st.button("Submit"):
|
105 |
-
# data = {
|
106 |
-
# "City": city,
|
107 |
-
# "Zip Code": zipcode,
|
108 |
-
# "Sex": sex,
|
109 |
-
# "LGBTQ": lgbtq,
|
110 |
-
# "Domestic Violence": domestic_violence,
|
111 |
-
# "Urgency": urgency,
|
112 |
-
# "Duration": duration,
|
113 |
-
# "Needs": needs
|
114 |
-
# }
|
115 |
-
|
116 |
-
# with open('data.json', 'w') as f:
|
117 |
-
# json.dump(data, f)
|
118 |
-
|
119 |
-
# st.session_state.form_submitted = True
|
120 |
-
# st.session_state.data = data
|
121 |
-
# st.rerun()
|
122 |
-
|
123 |
# Initialize session state
|
124 |
if 'form_submitted' not in st.session_state:
|
125 |
st.session_state.form_submitted = False
|
@@ -136,6 +103,8 @@ st.set_page_config(
|
|
136 |
st.title("ShelterSearch")
|
137 |
|
138 |
if not st.session_state.form_submitted:
|
|
|
|
|
139 |
city = st.selectbox("City", ['San Francisco', 'Oakland', 'Berkeley'])
|
140 |
zipcode = st.text_input("Zipcode")
|
141 |
|
@@ -170,77 +139,77 @@ else:
|
|
170 |
data = json.load(f)
|
171 |
st.json(data)
|
172 |
|
173 |
-
|
174 |
|
175 |
-
#
|
176 |
-
|
177 |
|
178 |
-
#
|
179 |
-
|
180 |
|
181 |
-
#
|
182 |
-
|
183 |
-
|
184 |
|
185 |
-
#
|
186 |
-
|
187 |
-
|
188 |
|
189 |
-
#
|
190 |
-
|
191 |
-
|
192 |
|
193 |
-
|
194 |
-
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
|
200 |
-
|
201 |
-
|
202 |
|
203 |
-
#
|
204 |
-
|
205 |
-
|
206 |
|
207 |
-
#
|
208 |
-
|
209 |
-
|
210 |
|
211 |
|
212 |
|
213 |
-
#
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
|
218 |
-
|
219 |
|
220 |
-
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
#
|
229 |
-
|
230 |
-
|
231 |
|
232 |
-
#
|
233 |
-
|
234 |
|
235 |
-
#
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
87 |
distance = R * c
|
88 |
return distance
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
# Initialize session state
|
91 |
if 'form_submitted' not in st.session_state:
|
92 |
st.session_state.form_submitted = False
|
|
|
103 |
st.title("ShelterSearch")
|
104 |
|
105 |
if not st.session_state.form_submitted:
|
106 |
+
st.write("Fill out this form")
|
107 |
+
|
108 |
city = st.selectbox("City", ['San Francisco', 'Oakland', 'Berkeley'])
|
109 |
zipcode = st.text_input("Zipcode")
|
110 |
|
|
|
139 |
data = json.load(f)
|
140 |
st.json(data)
|
141 |
|
142 |
+
shelters = pd.read_csv("database.csv")
|
143 |
|
144 |
+
# filter city
|
145 |
+
shelters = shelters[(shelters['City'] == data['City'])]
|
146 |
|
147 |
+
# filter sex
|
148 |
+
shelters = shelters[(shelters['Sex'] == data['Sex']) | (shelters['Sex'] == 'All')]
|
149 |
|
150 |
+
# filter lgbtq
|
151 |
+
if data['LGBTQ'] == 'No':
|
152 |
+
shelters = shelters[(shelters['LGBTQ'] == "No")]
|
153 |
|
154 |
+
# filter domestic violence
|
155 |
+
if data['Domestic Violence'] == "No":
|
156 |
+
shelters = shelters[(shelters['Domestic Violence'] == "No")]
|
157 |
|
158 |
+
# calculate distances between zipcodes
|
159 |
+
if data['Zip Code'] != "Unsure":
|
160 |
+
geocoding_api_key = os.environ['OpenWeather_API_KEY']
|
161 |
|
162 |
+
shelters_coordinates = shelters.apply(lambda row: get_coordinates(row['Zip Code'], geocoding_api_key), axis=1).tolist()
|
163 |
+
user_coordinates = get_coordinates(data['Zip Code'], geocoding_api_key)
|
164 |
|
165 |
+
distances = []
|
166 |
+
for coordinates in shelters_coordinates:
|
167 |
+
distances.append(haversine(coordinates[0], coordinates[1], user_coordinates[0], user_coordinates[1]))
|
168 |
|
169 |
+
max = max(distances) if (max(distances) != 0) else 1
|
170 |
+
shelters['zipcode_score'] = [d / max for d in distances]
|
171 |
|
172 |
+
# get urgency scores
|
173 |
+
urgency_scores = shelters.apply(lambda row: get_urgency_score(data['Urgency'], row['Urgency']), axis=1).tolist()
|
174 |
+
shelters['urgency_score'] = urgency_scores
|
175 |
|
176 |
+
# get duration scores
|
177 |
+
duration_scores = shelters.apply(lambda row: get_duration_score(data['Duration'], row['Duration']), axis=1).tolist()
|
178 |
+
shelters['duration_score'] = duration_scores
|
179 |
|
180 |
|
181 |
|
182 |
+
# services
|
183 |
+
if data['Needs'] != "":
|
184 |
+
services_scores = shelters.apply(lambda row: call_gpt(data['Needs'], row['Services']), axis=1).tolist()
|
185 |
+
services_scores = [s / 10 for s in services_scores]
|
186 |
|
187 |
+
shelters['services_score'] = services_scores
|
188 |
|
189 |
+
st.table(shelters)
|
190 |
|
191 |
+
shelters = [
|
192 |
+
{"title": "Shelter 1", "description": "This is the 1st shelter",},
|
193 |
+
{"title": "Shelter 2", "description": "This is the 2nd shelter.",},
|
194 |
+
{"title": "Shelter 3", "description": "This is the 3rd shelter.",}
|
195 |
+
]
|
196 |
+
|
197 |
+
# Display the current shelter information
|
198 |
+
shelter = shelters[st.session_state.shelter_index]
|
199 |
+
st.write(shelter["description"])
|
200 |
|
201 |
+
# Create two columns
|
202 |
+
col1, col2 = st.columns([1,1])
|
203 |
|
204 |
+
# Add buttons to each column
|
205 |
+
with col1:
|
206 |
+
if st.button("Previous"):
|
207 |
+
if st.session_state.shelter_index > 0:
|
208 |
+
st.session_state.shelter_index -= 1
|
209 |
+
st.experimental_rerun()
|
210 |
|
211 |
+
with col2:
|
212 |
+
if st.button("Next"):
|
213 |
+
if st.session_state.shelter_index < len(shelters) - 1:
|
214 |
+
st.session_state.shelter_index += 1
|
215 |
+
st.experimental_rerun()
|