Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import json
|
| 3 |
|
|
|
|
| 4 |
def validate_zipcode(zipcode):
|
| 5 |
try:
|
| 6 |
if len(zipcode) == 5 and zipcode.isdigit():
|
|
@@ -10,24 +11,17 @@ def validate_zipcode(zipcode):
|
|
| 10 |
except:
|
| 11 |
return False
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
st.
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
urgency = st.radio("Urgency", ("Immediate", "High", "Moderate", "General Inquiry"))
|
| 25 |
-
duration = st.radio("Duration", ("Long Term", "Transitional", "Temporary"))
|
| 26 |
-
needs = st.text_area("Needs (describe needed services + ideal qualities of shelter)")
|
| 27 |
-
|
| 28 |
-
submit_button = st.form_submit_button(label="Submit")
|
| 29 |
-
|
| 30 |
-
if submit_button:
|
| 31 |
if zipcode and not validate_zipcode(zipcode):
|
| 32 |
st.error("Please enter a valid 5-digit zipcode.")
|
| 33 |
else:
|
|
@@ -39,15 +33,23 @@ if not st.session_state.form_submitted:
|
|
| 39 |
"Duration": duration,
|
| 40 |
"Needs": needs
|
| 41 |
}
|
| 42 |
-
|
| 43 |
with open('data.json', 'w') as f:
|
| 44 |
json.dump(data, f)
|
| 45 |
-
|
| 46 |
st.session_state.form_submitted = True
|
| 47 |
-
st.
|
| 48 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
else:
|
| 50 |
-
st.success("Form
|
|
|
|
|
|
|
| 51 |
with open('data.json', 'r') as f:
|
| 52 |
data = json.load(f)
|
| 53 |
st.json(data)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import json
|
| 3 |
|
| 4 |
+
# Function to validate zipcode
|
| 5 |
def validate_zipcode(zipcode):
|
| 6 |
try:
|
| 7 |
if len(zipcode) == 5 and zipcode.isdigit():
|
|
|
|
| 11 |
except:
|
| 12 |
return False
|
| 13 |
|
| 14 |
+
# Function to handle form submission
|
| 15 |
+
@st.experimental_dialog("Fill out the form")
|
| 16 |
+
def form_dialog():
|
| 17 |
+
gender = st.radio("Gender", ("Male", "Female", "Other"))
|
| 18 |
+
city = st.radio("City", ("Oakland", "Berkeley", "SF"))
|
| 19 |
+
zipcode = st.text_input("Zipcode (Optional)", value="")
|
| 20 |
+
urgency = st.radio("Urgency", ("Immediate", "High", "Moderate", "General Inquiry"))
|
| 21 |
+
duration = st.radio("Duration", ("Long Term", "Transitional", "Temporary"))
|
| 22 |
+
needs = st.text_area("Needs (describe needed services + ideal qualities of shelter)")
|
| 23 |
+
|
| 24 |
+
if st.button("Submit"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
if zipcode and not validate_zipcode(zipcode):
|
| 26 |
st.error("Please enter a valid 5-digit zipcode.")
|
| 27 |
else:
|
|
|
|
| 33 |
"Duration": duration,
|
| 34 |
"Needs": needs
|
| 35 |
}
|
|
|
|
| 36 |
with open('data.json', 'w') as f:
|
| 37 |
json.dump(data, f)
|
|
|
|
| 38 |
st.session_state.form_submitted = True
|
| 39 |
+
st.session_state.data = data
|
| 40 |
+
st.rerun()
|
| 41 |
+
|
| 42 |
+
# Initialize session state
|
| 43 |
+
if 'form_submitted' not in st.session_state:
|
| 44 |
+
st.session_state.form_submitted = False
|
| 45 |
+
|
| 46 |
+
if not st.session_state.form_submitted:
|
| 47 |
+
if st.button("Open Form"):
|
| 48 |
+
form_dialog()
|
| 49 |
else:
|
| 50 |
+
st.success("Form submitted successfully!")
|
| 51 |
+
st.json(st.session_state.data)
|
| 52 |
+
|
| 53 |
with open('data.json', 'r') as f:
|
| 54 |
data = json.load(f)
|
| 55 |
st.json(data)
|