Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import json
|
3 |
+
|
4 |
+
def validate_zipcode(zipcode):
|
5 |
+
try:
|
6 |
+
if len(zipcode) == 5 and zipcode.isdigit():
|
7 |
+
return True
|
8 |
+
else:
|
9 |
+
return False
|
10 |
+
except:
|
11 |
+
return False
|
12 |
+
|
13 |
+
def main():
|
14 |
+
st.title("Information Form")
|
15 |
+
|
16 |
+
with st.form(key='info_form'):
|
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 |
+
submit_button = st.form_submit_button(label="Submit")
|
25 |
+
|
26 |
+
if submit_button:
|
27 |
+
if zipcode and not validate_zipcode(zipcode):
|
28 |
+
st.error("Please enter a valid 5-digit zipcode.")
|
29 |
+
else:
|
30 |
+
data = {
|
31 |
+
"Gender": gender,
|
32 |
+
"City": city,
|
33 |
+
"Zipcode": zipcode if zipcode else "N/A",
|
34 |
+
"Urgency": urgency,
|
35 |
+
"Duration": duration,
|
36 |
+
"Needs": needs
|
37 |
+
}
|
38 |
+
|
39 |
+
with open('data.json', 'w') as f:
|
40 |
+
json.dump(data, f)
|
41 |
+
|
42 |
+
st.success("Form submitted successfully!")
|
43 |
+
st.json(data)
|
44 |
+
|
45 |
+
if __name__ == '__main__':
|
46 |
+
main()
|