Spaces:
Sleeping
Sleeping
# import streamlit as st | |
# import time | |
# with st.form("my_input"): | |
# st.write("Input") | |
# # product | |
# product=st.text_input("product") | |
# # gender | |
# gender=st.radio("gender", ["male", "female"]) | |
# # profession | |
# profession=st.text_input("profession") | |
# # hobby | |
# hobby=st.text_input("hobby") | |
# # Every form must have a submit button. | |
# col1, col2=st.columns(2) | |
# # Place a button in each column | |
# with col1: | |
# submitted = st.form_submit_button("Submit") | |
# with col2: | |
# clear = st.form_submit_button("Clear") | |
# with st.form("my_output"): | |
# if submitted: | |
# st.write("product", product) | |
# st.write("gender", gender) | |
# st.write("profession", profession) | |
# st.write("hobby", hobby) | |
# # Clear the user inputs | |
# if clear: | |
# st.experimental_rerun() | |
# _LOREM_IPSUM = """ | |
# Lorem ipsum dolor sit amet, **consectetur adipiscing** elit, sed do eiusmod tempor | |
# incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis | |
# nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. | |
# """ | |
# def stream_data(): | |
# for word in _LOREM_IPSUM.split(" "): | |
# yield word + " " | |
# time.sleep(0.02) | |
# for word in _LOREM_IPSUM.split(" "): | |
# yield word + " " | |
# time.sleep(0.02) | |
# if st.button("Stream data"): | |
# st.write_stream(stream_data) | |
import streamlit as st | |
import SessionState | |
# Initialize session state | |
session_state = SessionState.get(product="", gender="", profession="", hobby="") | |
# Create a form for user inputs | |
with st.form("my_input"): | |
st.write("Input") | |
# product | |
product = st.text_input("product", value=session_state.product) | |
# gender | |
gender = st.radio("gender", ["male", "female"], index=["male", "female"].index(session_state.gender) if session_state.gender else 0) | |
# profession | |
profession = st.text_input("profession", value=session_state.profession) | |
# hobby | |
hobby = st.text_input("hobby", value=session_state.hobby) | |
# Every form must have a submit button. | |
submitted = st.form_submit_button("Submit") | |
clear = st.form_submit_button("Clear") | |
# Display the user inputs | |
with st.form("my_output"): | |
if submitted and not clear: | |
# Save inputs to session state | |
session_state.product = product | |
session_state.gender = gender | |
session_state.profession = profession | |
session_state.hobby = hobby | |
st.write("product", product) | |
st.write("gender", gender) | |
st.write("profession", profession) | |
st.write("hobby", hobby) | |
# Clear the user inputs | |
if clear: | |
# Clear session state | |
session_state.product = "" | |
session_state.gender = "" | |
session_state.profession = "" | |
session_state.hobby = "" | |
st.experimental_rerun() | |