Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -42,10 +42,12 @@ for message in st.session_state.messages:
|
|
42 |
else:
|
43 |
st.write(f"**Physics Master:** {message['content']}")
|
44 |
|
45 |
-
#
|
46 |
-
|
|
|
|
|
47 |
|
48 |
-
if user_input:
|
49 |
# Append user message
|
50 |
user_message = {'role': 'user', 'content': user_input}
|
51 |
st.session_state.messages.append(user_message)
|
@@ -77,9 +79,6 @@ if user_input:
|
|
77 |
# Display the full response as a paragraph
|
78 |
st.write(f"**Physics Master:** {full_response}")
|
79 |
|
80 |
-
# Reset user input box
|
81 |
-
st.session_state.user_input = ""
|
82 |
-
|
83 |
# Save the chat history to a JSON file
|
84 |
with open('chat_history.json', 'w', encoding='utf8') as file:
|
85 |
json.dump(st.session_state.messages, file, indent=4)
|
|
|
42 |
else:
|
43 |
st.write(f"**Physics Master:** {message['content']}")
|
44 |
|
45 |
+
# Use a form to manage user input and submission
|
46 |
+
with st.form(key="input_form", clear_on_submit=True):
|
47 |
+
user_input = st.text_input("Ask a question", key="user_input")
|
48 |
+
submit_button = st.form_submit_button(label="Send")
|
49 |
|
50 |
+
if submit_button and user_input:
|
51 |
# Append user message
|
52 |
user_message = {'role': 'user', 'content': user_input}
|
53 |
st.session_state.messages.append(user_message)
|
|
|
79 |
# Display the full response as a paragraph
|
80 |
st.write(f"**Physics Master:** {full_response}")
|
81 |
|
|
|
|
|
|
|
82 |
# Save the chat history to a JSON file
|
83 |
with open('chat_history.json', 'w', encoding='utf8') as file:
|
84 |
json.dump(st.session_state.messages, file, indent=4)
|