mmaleki92 commited on
Commit
d5172bb
·
verified ·
1 Parent(s): 28f05b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
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
- # Input for user to ask questions
46
- user_input = st.text_input("Ask a question", key="user_input")
 
 
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)