Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,48 +10,44 @@ def validate_zipcode(zipcode):
|
|
| 10 |
except:
|
| 11 |
return False
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
if
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
st.json(data)
|
| 55 |
-
|
| 56 |
-
if __name__ == '__main__':
|
| 57 |
-
main()
|
|
|
|
| 10 |
except:
|
| 11 |
return False
|
| 12 |
|
| 13 |
+
st.title("Information Form")
|
| 14 |
+
|
| 15 |
+
# Initialize session state
|
| 16 |
+
if 'form_submitted' not in st.session_state:
|
| 17 |
+
st.session_state.form_submitted = False
|
| 18 |
+
|
| 19 |
+
if not st.session_state.form_submitted:
|
| 20 |
+
with st.form(key='info_form'):
|
| 21 |
+
gender = st.radio("Gender", ("Male", "Female", "Other"))
|
| 22 |
+
city = st.radio("City", ("Oakland", "Berkeley", "SF"))
|
| 23 |
+
zipcode = st.text_input("Zipcode (Optional)", value="")
|
| 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:
|
| 34 |
+
data = {
|
| 35 |
+
"Gender": gender,
|
| 36 |
+
"City": city,
|
| 37 |
+
"Zipcode": zipcode if zipcode else "N/A",
|
| 38 |
+
"Urgency": urgency,
|
| 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.success("Form submitted successfully!")
|
| 48 |
+
st.json(data)
|
| 49 |
+
else:
|
| 50 |
+
st.success("Form already submitted.")
|
| 51 |
+
with open('data.json', 'r') as f:
|
| 52 |
+
data = json.load(f)
|
| 53 |
+
st.json(data)
|
|
|
|
|
|
|
|
|
|
|
|