Spaces:
Running
Running
Update app.py
Browse files
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)
|
76 |
-
st.markdown("**Or choose an example question:**")
|
77 |
for example in cfg.examples:
|
78 |
-
if st.button(example
|
79 |
-
user_input = example
|
80 |
-
|
|
|
|
|
|
|
|
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
st.session_state.messages.append(
|
87 |
-
|
88 |
-
|
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()
|