From af073856b568daddd30ea81ae95034ebdfec534e Mon Sep 17 00:00:00 2001 From: Tang Chengrui Date: Tue, 24 Sep 2024 15:44:41 +0000 Subject: [PATCH] Add streamlit demo program --- hello.py | 6 ++++++ streamlit_test1.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 hello.py create mode 100644 streamlit_test1.py diff --git a/hello.py b/hello.py new file mode 100644 index 0000000..961a11d --- /dev/null +++ b/hello.py @@ -0,0 +1,6 @@ +import streamlit as st +# Create a text input box +text_input = st.text_input("Enter some text:") +# Create a submit button +if st.button("Submit"): +st.write("You've inputted:", text_input) \ No newline at end of file diff --git a/streamlit_test1.py b/streamlit_test1.py new file mode 100644 index 0000000..30667b7 --- /dev/null +++ b/streamlit_test1.py @@ -0,0 +1,25 @@ +import streamlit as st + +# Initialize session state for storing past inputs +if 'text_history' not in st.session_state: + st.session_state.text_history = [] + +# Create a text input box +text_input = st.text_input("Enter some text:") + +# Create a submit button +submit_button = st.button("Submit") +if submit_button: + st.session_state.text_history.append(text_input) + st.write("You've inputted:", text_input) + st.session_state.input_box = "" # Clear the input box + +# Create a clear button +clear_button = st.button("Clear History") +if clear_button: + st.session_state.text_history = [] + +# Display the list of past submitted input +st.write("## Past inputs") +for text in st.session_state.text_history: + st.write(text) \ No newline at end of file