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