Easonwangzk commited on
Commit
9c1115e
·
1 Parent(s): 09edc25

Fix: Add st.rerun() to example buttons to prevent blank page 3

Browse files
Files changed (1) hide show
  1. src/app.py +7 -9
src/app.py CHANGED
@@ -44,9 +44,13 @@ st.set_page_config(
44
  layout="wide"
45
  )
46
 
47
- # Initialize config
48
  if 'config' not in st.session_state:
49
  st.session_state.config = Config()
 
 
 
 
50
 
51
  # Sidebar configuration
52
  with st.sidebar:
@@ -103,12 +107,6 @@ if not st.session_state.config.is_valid():
103
  st.error("Please set OPENAI_API_KEY in your .env file or environment variables.")
104
  st.stop()
105
 
106
- # Initialize example state if not exists
107
- if 'example_text' not in st.session_state:
108
- st.session_state.example_text = ''
109
- if 'example_question' not in st.session_state:
110
- st.session_state.example_question = ''
111
-
112
  # Example texts for quick testing
113
  with st.expander("Try Example Texts"):
114
  col1, col2, col3 = st.columns(3)
@@ -135,7 +133,7 @@ with st.expander("Try Example Texts"):
135
  st.markdown("#### Text to Analyze")
136
  text_input = st.text_area(
137
  "text_input",
138
- value=st.session_state.get('example_text', ''),
139
  height=200,
140
  placeholder="Enter the text you want to analyze here...",
141
  help="Paste or type the text you want the agent to analyze",
@@ -146,7 +144,7 @@ text_input = st.text_area(
146
  st.markdown("#### Your Question")
147
  question_input = st.text_input(
148
  "question_input",
149
- value=st.session_state.get('example_question', ''),
150
  placeholder="e.g., What is the sentiment of this text? What are the main keywords?",
151
  help="Ask a question about the text",
152
  label_visibility="collapsed"
 
44
  layout="wide"
45
  )
46
 
47
+ # Initialize config and example state
48
  if 'config' not in st.session_state:
49
  st.session_state.config = Config()
50
+ if 'example_text' not in st.session_state:
51
+ st.session_state.example_text = ''
52
+ if 'example_question' not in st.session_state:
53
+ st.session_state.example_question = ''
54
 
55
  # Sidebar configuration
56
  with st.sidebar:
 
107
  st.error("Please set OPENAI_API_KEY in your .env file or environment variables.")
108
  st.stop()
109
 
 
 
 
 
 
 
110
  # Example texts for quick testing
111
  with st.expander("Try Example Texts"):
112
  col1, col2, col3 = st.columns(3)
 
133
  st.markdown("#### Text to Analyze")
134
  text_input = st.text_area(
135
  "text_input",
136
+ value=st.session_state.example_text,
137
  height=200,
138
  placeholder="Enter the text you want to analyze here...",
139
  help="Paste or type the text you want the agent to analyze",
 
144
  st.markdown("#### Your Question")
145
  question_input = st.text_input(
146
  "question_input",
147
+ value=st.session_state.example_question,
148
  placeholder="e.g., What is the sentiment of this text? What are the main keywords?",
149
  help="Ask a question about the text",
150
  label_visibility="collapsed"