Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import json
|
| 3 |
|
| 4 |
# Function to validate zipcode
|
|
@@ -46,26 +47,14 @@ if 'form_submitted' not in st.session_state:
|
|
| 46 |
if 'shelter_index' not in st.session_state:
|
| 47 |
st.session_state.shelter_index = 0
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
"title": "Shelter 2",
|
| 58 |
-
"description": "This is the 2nd shelter. API Call will generate this outcome....",
|
| 59 |
-
"header": "A dog",
|
| 60 |
-
"image_url": "https://static.streamlit.io/examples/dog.jpg"
|
| 61 |
-
},
|
| 62 |
-
{
|
| 63 |
-
"title": "Shelter 3",
|
| 64 |
-
"description": "This is the 3rd shelter. API Call will generate this outcome....",
|
| 65 |
-
"header": "An owl",
|
| 66 |
-
"image_url": "https://static.streamlit.io/examples/owl.jpg"
|
| 67 |
-
}
|
| 68 |
-
]
|
| 69 |
|
| 70 |
# Page config
|
| 71 |
st.set_page_config(
|
|
@@ -95,26 +84,53 @@ else:
|
|
| 95 |
# Display
|
| 96 |
st.json(data)
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
import json
|
| 4 |
|
| 5 |
# Function to validate zipcode
|
|
|
|
| 47 |
if 'shelter_index' not in st.session_state:
|
| 48 |
st.session_state.shelter_index = 0
|
| 49 |
|
| 50 |
+
# Load the master database
|
| 51 |
+
master_database = pd.DataFrame({
|
| 52 |
+
"gender": ["Male", "Female", "Other", "Male", "Female", "Other"],
|
| 53 |
+
"city": ["Oakland", "Berkeley", "SF", "SF", "Oakland", "Berkeley"],
|
| 54 |
+
"zipcode": ["94612", "94704", "94103", "94103", "94612", "94704"],
|
| 55 |
+
"duration": ["Long Term", "Transitional", "Temporary", "Long Term", "Transitional", "Temporary"],
|
| 56 |
+
"needs": ["Food and shelter", "Medical assistance", "Job placement", "Food and job", "Medical and shelter", "Shelter and education"]
|
| 57 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# Page config
|
| 60 |
st.set_page_config(
|
|
|
|
| 84 |
# Display
|
| 85 |
st.json(data)
|
| 86 |
|
| 87 |
+
# Filter the master database
|
| 88 |
+
filtered_data = master_database[
|
| 89 |
+
(master_database['gender'] == data['Gender']) &
|
| 90 |
+
(master_database['city'] == data['City']) &
|
| 91 |
+
(master_database['duration'] == data['Duration']) &
|
| 92 |
+
(master_database['needs'].str.contains(data['Needs'], case=False))
|
| 93 |
+
]
|
| 94 |
+
|
| 95 |
+
# Create the client database
|
| 96 |
+
client_database = filtered_data.to_dict(orient='records')
|
| 97 |
+
|
| 98 |
+
# Convert client_database to shelters format
|
| 99 |
+
shelters = [
|
| 100 |
+
{
|
| 101 |
+
"title": f"Shelter {i+1}",
|
| 102 |
+
"description": f"This is shelter {i+1}.",
|
| 103 |
+
"header": "Details",
|
| 104 |
+
"image_url": "https://static.streamlit.io/examples/cat.jpg" if i % 2 == 0 else "https://static.streamlit.io/examples/dog.jpg",
|
| 105 |
+
"info": row
|
| 106 |
+
}
|
| 107 |
+
for i, row in enumerate(client_database)
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
if len(shelters) == 0:
|
| 111 |
+
st.warning("No shelters found matching your criteria.")
|
| 112 |
+
else:
|
| 113 |
+
# Display the current shelter information
|
| 114 |
+
shelter = shelters[st.session_state.shelter_index]
|
| 115 |
+
st.write(shelter["description"])
|
| 116 |
+
st.header(shelter["header"])
|
| 117 |
+
st.image(shelter["image_url"])
|
| 118 |
+
st.json(shelter["info"])
|
| 119 |
+
|
| 120 |
+
# Navigation buttons
|
| 121 |
+
col1, col2, col3 = st.columns([1, 1, 1])
|
| 122 |
+
|
| 123 |
+
with col1:
|
| 124 |
+
if st.button("Previous"):
|
| 125 |
+
if st.session_state.shelter_index > 0:
|
| 126 |
+
st.session_state.shelter_index -= 1
|
| 127 |
+
st.experimental_rerun()
|
| 128 |
+
|
| 129 |
+
with col2:
|
| 130 |
+
st.write("")
|
| 131 |
+
|
| 132 |
+
with col3:
|
| 133 |
+
if st.button("Next"):
|
| 134 |
+
if st.session_state.shelter_index < len(shelters) - 1:
|
| 135 |
+
st.session_state.shelter_index += 1
|
| 136 |
+
st.experimental_rerun()
|