awacke1 commited on
Commit
fdfcd02
·
1 Parent(s): cef716e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -1 +1,45 @@
1
- # AutoInflatable-LifeCraft-Vessel-BoatDesign
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AutoInflatable-LifeCraft-Vessel-BoatDesign
2
+
3
+ import streamlit as st
4
+ import csv
5
+ import os
6
+
7
+ # Define function to save form data as text file
8
+ def save_data(name, email, phone):
9
+ with open('community.csv', mode='a') as csv_file:
10
+ fieldnames = ['Name', 'Email', 'Phone']
11
+ writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
12
+ if os.stat('community.csv').st_size == 0:
13
+ writer.writeheader()
14
+ writer.writerow({'Name': name, 'Email': email, 'Phone': phone})
15
+ with open(f'{name}.txt', mode='w') as file:
16
+ file.write(f'Name: {name}\nEmail: {email}\nPhone: {phone}')
17
+
18
+ # Define function to reset form data
19
+ def reset_data():
20
+ os.remove('community.csv')
21
+ for file in os.listdir():
22
+ if file.endswith('.txt'):
23
+ os.remove(file)
24
+
25
+ # Define Streamlit app
26
+ def app():
27
+ st.title('Community Hub Form')
28
+
29
+ # Get form inputs
30
+ name = st.text_input('Name')
31
+ email = st.text_input('Email')
32
+ phone = st.text_input('Phone')
33
+
34
+ # Save form data when user submits
35
+ if st.button('Submit'):
36
+ save_data(name, email, phone)
37
+ st.success('Form submitted!')
38
+
39
+ # Reset form data when user clicks button
40
+ if st.button('Reset'):
41
+ reset_data()
42
+ st.success('Data reset!')
43
+
44
+ if __name__ == '__main__':
45
+ app()