I am using streamlit - 1.39.0 when I rerun the previous elements visual as ghost elements I attached the image for ref and this is my current code
import streamlit as st
from chains.book_brainstorm_chain import book_brainstorm_chain
def home_page():
st.title("Story Writer App")
# Input fields
st.session_state.summary = st.text_input("π Story Summary", value=st.session_state.summary)
st.session_state.details = st.text_area("π Story Details", value=st.session_state.details)
st.session_state.style = st.text_input("π Story Style", value=st.session_state.style)
# Button to start brainstorming
if st.button("π Start BrainStorming"):
st.session_state.state = "BRAINSTORMING"
st.rerun()
def brainstorming_page():
st.header("Story Ideas")
# Show the brainstorm output in the main area
if st.session_state.story_brainstrom_ideas is None:
with st.spinner("π§ Brainstorming ideas..."):
st.session_state.story_brainstrom_ideas = st.write_stream(book_brainstorm_chain.stream({
'story_summary': st.session_state.summary,
'story_details': st.session_state.details,
'story_style': st.session_state.style
}))
else:
st.write(st.session_state.story_brainstrom_ideas)
col1, col2, col3, _ = st.columns([2, 2, 2, 3], vertical_alignment="bottom")
with col1:
st.session_state.idea_selected = st.selectbox("Select Brainstorming Idea", range(1, 6))
with col2:
if st.button("β
Select"):
st.write(f"Selected Idea: {st.session_state.idea_selected}")
with col3:
if st.button("π Regenerate"):
st.session_state.state = "BRAINSTORMING"
st.session_state.story_brainstrom_ideas = None
st.rerun()
def main():
st.set_page_config(layout="wide")
# Initialize session state variables if not already set
if 'state' not in st.session_state:
st.session_state.state = "INITIAL"
if 'summary' not in st.session_state:
st.session_state.summary = ""
if 'details' not in st.session_state:
st.session_state.details = ""
if 'style' not in st.session_state:
st.session_state.style = ""
if 'story_brainstrom_ideas' not in st.session_state:
st.session_state.story_brainstrom_ideas = None
if 'idea_selected' not in st.session_state:
st.session_state.idea_selected = 0
if st.session_state.state == "INITIAL":
home_page()
elif st.session_state.state == "BRAINSTORMING":
brainstorming_page()
if __name__ == "__main__":
main()