AI-poems / app.py
mellymeldubs's picture
Update app.py
b8e357d verified
import streamlit as st
import pandas as pd
import os
# Title of the Streamlit app
st.title('Poem Submission to CSV')
# Poetic forms
poetic_forms = ['Haiku', 'Sonnet', 'Limerick', 'Free Verse', 'Ballad']
# Create input fields for user data
poem = st.text_input('Poem Text')
#age = st.number_input('Age', min_value=0, max_value=120, step=1)
#email = st.text_input('Email')
poetic_form = st.selectbox('Select Poetic Form', poetic_forms)
# Define the CSV file path
file_path = 'poem_data.csv'
print(pd.read_csv(file_path))
# Create a button to submit the data
if st.button('Submit'):
# Create a DataFrame from the input data
new_data = pd.DataFrame([{'text': [poem], 'form': [poetic_form]}])
# Check if the file already exists
#if os.path.exists(file_path):
# If the file exists, append the new data without writing the header
new_data.to_csv(file_path, mode='a', header=False, index=False)
# else:
# # If the file does not exist, create it and write the header
# new_data.to_csv(file_path, mode='w', header=True, index=False)
st.success('Poem submitted successfully!')
# # Display the content of the CSV file
# if os.path.exists(file_path):
# st.subheader('Current Data')
# data = pd.read_csv(file_path)
# st.write(data)
# Calculate the number of poems for each poetic form
# poem_counts = pd.read_csv(file_path)['form'].value_counts().reindex(poetic_forms, fill_value=0)
# # Display progress bars for each poetic form
# st.subheader('Poem Submission Progress')
# for form in poetic_forms:
# st.write(f"{form}: {poem_counts[form]} / 100")
# st.progress(min(poem_counts[form], 100) / 100)