EmailGeneration / app.py
Mia2024's picture
pr19 (#19)
2f0136f verified
raw
history blame
2.4 kB
import streamlit as st
from utils import generate_email
col1, col2=st.columns(2)
with col1:
with st.container(height=500):
with st.form("my_input", clear_on_submit=True, border=False):
st.write("Input")
# product
product=st.text_input("product", key="product")
# gender
gender=st.radio("gender", ["male", "female", "non-binary"], key="gender")
# profession
profession=st.text_input("profession", key="profession")
# hobby
hobby=st.text_input("hobby", key="hobby")
# Every form must have a submit button.
submitted = st.form_submit_button(label='Submit')
# if submitted:
# response = generate_email(st.session_state.product, st.session_state.gender, st.session_state.profession, st.session_state.hobby)
# st.session_state.email=response
with col2:
if submitted:
with st.spinner('Wait for it...'):
response = generate_email(st.session_state.product, st.session_state.gender, st.session_state.profession, st.session_state.hobby)
st.session_state.email=response
print("st.session_state.email")
print(st.session_state.email)
with st.container(height=500):
placeholder = st.empty()
# Replace the chart with several elements:
with placeholder.container():
st.write("Product: " + st.session_state.product)
st.write("Gender: " + st.session_state.gender)
st.write("Profession: " + st.session_state.profession)
st.write("Hobby: "+ st.session_state.hobby)
st.write("Email: "+ st.session_state.email)
if 'clicked' not in st.session_state:
st.session_state.clicked = False
def click_button():
st.session_state.clicked = True
st.button('Clear', on_click=click_button)
if st.session_state.clicked:
# The message and nested widget will remain on the page
del st.session_state.product
del st.session_state.gender
del st.session_state.profession
del st.session_state.hobby
del st.session_state.email
del st.session_state.clicked
if submitted:
placeholder.empty()