ofermend commited on
Commit
0160239
1 Parent(s): c582153

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -72,29 +72,23 @@ def launch_bot():
72
  user_input = st.text_input("Type your question here...", key="user_input")
73
 
74
  # Display example questions only during the first round
75
- if len(st.session_state.messages) <= 1: # Adjust based on when you want examples to disappear
76
- st.markdown("**Or choose an example question:**")
77
  for example in cfg.examples:
78
- if st.button(example, key=example):
79
- user_input = example
80
- st.session_state['user_input'] = user_input
 
 
 
 
81
 
82
- # Check if there's input to process (either typed or selected from examples)
83
- if user_input:
84
- # This block prevents immediate processing when the page loads. Adjust as necessary.
85
- if "processed" not in st.session_state or not st.session_state["processed"]:
86
- st.session_state.messages.append({"role": "user", "content": user_input})
87
- with st.chat_message("assistant"):
88
- with st.spinner("Thinking..."):
89
- response = generate_response(user_input)
90
- st.write(response)
91
- st.session_state.messages.append({"role": "assistant", "content": response})
92
- st.session_state["processed"] = True # Prevent re-processing the same input on refresh
93
 
94
- # Clear the input for the next message
95
- st.session_state['user_input'] = ''
96
- st.experimental_rerun() # Rerun the app to clear the input box
97
-
98
-
99
  if __name__ == "__main__":
100
  launch_bot()
 
72
  user_input = st.text_input("Type your question here...", key="user_input")
73
 
74
  # Display example questions only during the first round
75
+ if len(st.session_state.messages) == 0: # Only show examples in the first round
 
76
  for example in cfg.examples:
77
+ if st.button(example):
78
+ user_input = example # Directly use the example as input
79
+ # Process the input immediately
80
+ response = generate_response(user_input)
81
+ st.session_state.messages.append(user_input)
82
+ st.session_state.messages.append(response)
83
+ st.experimental_rerun() # Rerun to refresh and show the response
84
 
85
+ if st.button("Submit"):
86
+ if user_input: # Ensure there's something to process
87
+ response = generate_response(user_input)
88
+ st.session_state.messages.append(user_input)
89
+ st.session_state.messages.append(response)
90
+ # Clear the input (workaround as direct clearing isn't supported)
91
+ st.experimental_rerun() # Rerun to refresh and clear the input box
 
 
 
 
92
 
 
 
 
 
 
93
  if __name__ == "__main__":
94
  launch_bot()