Spaces:
Running
Running
File size: 3,937 Bytes
54c32b3 f9807fc de80335 f9807fc c34798a 60682c0 5e7b531 60682c0 5e7b531 60682c0 5e7b531 60682c0 5e7b531 60682c0 5e7b531 60682c0 5e7b531 60682c0 5e7b531 60682c0 de80335 60682c0 c34798a 54b78c7 c34798a 60682c0 c34798a 60682c0 0e5c52a 60682c0 0e5c52a e7f9460 0e5c52a e7f9460 0e5c52a db8ea7d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
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("""
<style>
.chat-container {
width: 100%;
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
font-family: Arial, sans-serif;
}
.chat-box {
height: 350px;
overflow-y: auto;
border: 1px solid #ddd;
padding: 10px;
background-color: #f9f9f9;
margin-bottom: 10px;
border-radius: 5px;
}
.message {
margin: 10px 0;
padding: 10px;
border-radius: 5px;
max-width: 70%;
word-wrap: break-word;
color: #000000; /* ensures text is visible */
}
.user-message {
background-color: #e1f5fe;
color: #000000; /* dark text */
align-self: flex-end;
margin-left: auto;
}
.bot-message {
background-color: #f1f1f1;
color: #000000; /* dark text */
align-self: flex-start;
margin-right: auto;
}
/* Optional: Dark mode support */
@media (prefers-color-scheme: dark) {
.chat-container {
background-color: #1e1e1e;
color: #ffffff;
}
.chat-box {
background-color: #2a2a2a;
border: 1px solid #444;
}
.message {
color: #ffffff;
}
.user-message {
background-color: #1565c0;
color: #ffffff;
}
.bot-message {
background-color: #333333;
color: #ffffff;
}
}
</style>
""", unsafe_allow_html=True)
st.markdown("## π€α
αα α α ααα α¨α€α α αα«αͺ", unsafe_allow_html=True)
st.markdown("α΅α ααα΅α α¨α α£ααα α α½α³ α₯α«α α αα΅? α₯α£αα α«ααα‘α’", unsafe_allow_html=True)
# Chat container and message display
#st.markdown('<div class="chat-container">', unsafe_allow_html=True)
#st.markdown('<div class="chat-box">', 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'<div class="message {css_class}">{msg["text"]}</div>', unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True) # Close chat-box
st.markdown('</div>', 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})
|