import streamlit as st
from chatbot_utils import AmharicChatbot
st.set_page_config(page_title="ቅመም በአማርኛ የጤና አማካሪ", layout="centered")
@st.cache_resource
def load_bot():
return AmharicChatbot("amharic_srh_qa.csv")
bot = load_bot()
# Inject CSS for chat style
st.markdown("""
""", unsafe_allow_html=True)
st.markdown("## 🤖ቅመም በአማርኛ የጤና አማካሪ", unsafe_allow_html=True)
st.markdown("ስለ ወሊድና የአባላዘር በሽታ ጥያቄ አሎት? እባክዎ ያቀርቡ።", unsafe_allow_html=True)
# Chat container and message display
#st.markdown('
', unsafe_allow_html=True)
#st.markdown('
', unsafe_allow_html=True)
if "messages" not in st.session_state:
st.session_state.messages = []
for msg in st.session_state.messages:
css_class = "user-message" if msg["sender"] == "user" else "bot-message"
st.markdown(f'
{msg["text"]}
', unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True) # Close chat-box
st.markdown('
', unsafe_allow_html=True) # Close chat-container
# Form with clear_on_submit and direct input capture
with st.form(key="chat_form", clear_on_submit=True):
user_input = st.text_input("💬 ጥያቄዎን ያስገቡ:")
submit = st.form_submit_button("መልስ አውጣ")
if submit:
if user_input.strip() == "":
st.warning("እባክዎ ጥያቄ ያስገቡ።")
else:
# Append user input
st.session_state.messages.append({"sender": "user", "text": user_input})
# Generate response
response = bot.get_answer(user_input)
if response == "__OUT_OF_SCOPE__":
response = "ይቅርታ፣ ይህንን ጥያቄ ማስተዋል አልቻልኩም ከእኔ መረጃ ውጪ ነው። እባክዎ በሌላ መንገድ ይሞክሩ።"
# Append bot response
st.session_state.messages.append({"sender": "bot", "text": response})