Spaces:
Build error
Build error
File size: 2,917 Bytes
fdfcd02 3887b17 fdfcd02 3887b17 fdfcd02 3887b17 fdfcd02 3887b17 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# AutoInflatable-LifeCraft-Vessel-BoatDesign
import streamlit as st
import csv
import os
import random
# 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}\n')
# 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 function to show data after three views
def show_data():
count = 0
with open('community.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
count += 1
if count == 3:
st.write(f'{row["Name"]}: {row["Email"]} - {row["Phone"]}')
count = 0
# 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!')
# Show data when user clicks button
if st.button('Show data'):
show_data()
# Reply and vote buttons
st.write('Emails/SMS')
with open('community.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
name = row['Name']
email = row['Email']
phone = row['Phone']
st.write(f'{name}: {email} - {phone}')
if st.button('Reply', key=f'reply_{name}'):
st.text_input(f'Reply to {name}')
if st.button(f'Vote up {name}'):
st.success(f'{name} has been voted up!')
if st.button(f'No thanks to {name}'):
st.warning(f'{name} has been voted down!')
with open(f'{name}.txt', mode='w') as file:
file.write(f'Life points: 0\n')
st.write('')
# Add tip and emoji
st.write('Add tip')
tip = st.text_input('Tip')
if st.button('Submit tip'):
emoji = random.choice(['👍', '👌', '👏', '💡'])
with open(f'{name}.txt', mode='a') as file:
file.write(f'Tip: {tip} {emoji}\nLife points: 10\n')
st.success('Tip submitted!')
if __name__ == '__main__':
app() |