eagle0504 commited on
Commit
9d09d99
·
verified ·
1 Parent(s): f8bbc95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -45
app.py CHANGED
@@ -10,48 +10,44 @@ def validate_zipcode(zipcode):
10
  except:
11
  return False
12
 
13
- def main():
14
- st.title("Information Form")
15
-
16
- # Initialize session state
17
- if 'form_submitted' not in st.session_state:
18
- st.session_state.form_submitted = False
19
-
20
- if not st.session_state.form_submitted:
21
- with st.form(key='info_form'):
22
- gender = st.radio("Gender", ("Male", "Female", "Other"))
23
- city = st.radio("City", ("Oakland", "Berkeley", "SF"))
24
- zipcode = st.text_input("Zipcode (Optional)", value="")
25
- urgency = st.radio("Urgency", ("Immediate", "High", "Moderate", "General Inquiry"))
26
- duration = st.radio("Duration", ("Long Term", "Transitional", "Temporary"))
27
- needs = st.text_area("Needs (describe needed services + ideal qualities of shelter)")
28
-
29
- submit_button = st.form_submit_button(label="Submit")
30
-
31
- if submit_button:
32
- if zipcode and not validate_zipcode(zipcode):
33
- st.error("Please enter a valid 5-digit zipcode.")
34
- else:
35
- data = {
36
- "Gender": gender,
37
- "City": city,
38
- "Zipcode": zipcode if zipcode else "N/A",
39
- "Urgency": urgency,
40
- "Duration": duration,
41
- "Needs": needs
42
- }
43
-
44
- with open('data.json', 'w') as f:
45
- json.dump(data, f)
46
-
47
- st.session_state.form_submitted = True
48
- st.success("Form submitted successfully!")
49
- st.json(data)
50
- else:
51
- st.success("Form already submitted.")
52
- with open('data.json', 'r') as f:
53
- data = json.load(f)
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)