Walelign commited on
Commit
e7f9460
Β·
verified Β·
1 Parent(s): 54b78c7

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -68,26 +68,31 @@ for msg in st.session_state.messages:
68
  st.markdown('</div>', unsafe_allow_html=True) # Close chat-box
69
  st.markdown('</div>', unsafe_allow_html=True) # Close chat-container
70
 
 
 
 
71
  with st.form(key="chat_form"):
72
- st.text_input("πŸ’¬ αŒ₯α‹«α‰„α‹ŽαŠ• α‹«αˆ΅αŒˆα‰‘:", key="input")
73
  submit = st.form_submit_button("መልሡ αŠ α‹αŒ£")
74
 
75
  if submit:
76
- user_input = st.session_state.input.strip()
77
 
78
  if user_input == "":
79
  st.warning("αŠ₯α‰£αŠ­α‹Ž αŒ₯ያቄ α‹«αˆ΅αŒˆα‰‘α’")
80
  else:
81
- # Append user message
82
  st.session_state.messages.append({"sender": "user", "text": user_input})
83
 
84
- # Get bot response
85
  response = bot.get_answer(user_input)
86
-
87
  if response == "__OUT_OF_SCOPE__":
88
  response = "α‹­α‰…αˆ­α‰³α£ α‹­αˆ…αŠ•αŠ• αŒ₯ያቄ αˆ›αˆ΅α‰°α‹‹αˆ αŠ αˆα‰»αˆαŠ©αˆα’ αŠ₯α‰£αŠ­α‹Ž α‰ αˆŒαˆ‹ αˆ˜αŠ•αŒˆα‹΅ α‹­αˆžαŠ­αˆ©α’"
89
 
90
- # Append bot message
91
  st.session_state.messages.append({"sender": "bot", "text": response})
92
 
 
 
 
 
93
 
 
68
  st.markdown('</div>', unsafe_allow_html=True) # Close chat-box
69
  st.markdown('</div>', unsafe_allow_html=True) # Close chat-container
70
 
71
+ if "input" not in st.session_state:
72
+ st.session_state.input = ""
73
+
74
  with st.form(key="chat_form"):
75
+ user_input = st.text_input("πŸ’¬ αŒ₯α‹«α‰„α‹ŽαŠ• α‹«αˆ΅αŒˆα‰‘:", value=st.session_state.input, key="input_form")
76
  submit = st.form_submit_button("መልሡ αŠ α‹αŒ£")
77
 
78
  if submit:
79
+ user_input = st.session_state.input_form.strip()
80
 
81
  if user_input == "":
82
  st.warning("αŠ₯α‰£αŠ­α‹Ž αŒ₯ያቄ α‹«αˆ΅αŒˆα‰‘α’")
83
  else:
84
+ # Append user input
85
  st.session_state.messages.append({"sender": "user", "text": user_input})
86
 
87
+ # Generate response
88
  response = bot.get_answer(user_input)
 
89
  if response == "__OUT_OF_SCOPE__":
90
  response = "α‹­α‰…αˆ­α‰³α£ α‹­αˆ…αŠ•αŠ• αŒ₯ያቄ αˆ›αˆ΅α‰°α‹‹αˆ αŠ αˆα‰»αˆαŠ©αˆα’ αŠ₯α‰£αŠ­α‹Ž α‰ αˆŒαˆ‹ αˆ˜αŠ•αŒˆα‹΅ α‹­αˆžαŠ­αˆ©α’"
91
 
 
92
  st.session_state.messages.append({"sender": "bot", "text": response})
93
 
94
+ # Reset input manually
95
+ st.session_state.input_form = ""
96
+
97
+
98