Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,103 @@
|
|
1 |
-
|
2 |
import streamlit as st
|
3 |
from chatbot_utils import AmharicChatbot
|
4 |
|
5 |
st.set_page_config(page_title="Amharic SRH Chatbot", layout="centered")
|
6 |
|
7 |
-
|
8 |
-
st.markdown("ስለ ወሊድና የአባላዘር በሽታ ጥያቄ አሎት? እባክዎ ያቀርቡ።")
|
9 |
-
|
10 |
@st.cache_resource
|
11 |
def load_bot():
|
12 |
return AmharicChatbot("amharic_srh_qa.csv")
|
13 |
|
14 |
bot = load_bot()
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
if query:
|
20 |
-
results = bot.get_answer(query)
|
21 |
-
for i, (q, a) in enumerate(results):
|
22 |
-
st.write(f"**Q{i+1}:** {q}")
|
23 |
-
st.success(f"**A{i+1}:** {a}")
|
24 |
-
else:
|
25 |
-
st.warning("እባክዎ ጥያቄ ያስገቡ።")
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from chatbot_utils import AmharicChatbot
|
3 |
|
4 |
st.set_page_config(page_title="Amharic SRH Chatbot", layout="centered")
|
5 |
|
6 |
+
# Load the chatbot
|
|
|
|
|
7 |
@st.cache_resource
|
8 |
def load_bot():
|
9 |
return AmharicChatbot("amharic_srh_qa.csv")
|
10 |
|
11 |
bot = load_bot()
|
12 |
|
13 |
+
# Inject Custom CSS
|
14 |
+
st.markdown("""
|
15 |
+
<style>
|
16 |
+
.chat-container {
|
17 |
+
width: 100%;
|
18 |
+
max-width: 600px;
|
19 |
+
margin: 0 auto;
|
20 |
+
background-color: white;
|
21 |
+
padding: 20px;
|
22 |
+
border-radius: 10px;
|
23 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
|
24 |
+
}
|
25 |
+
.chat-box {
|
26 |
+
height: 350px;
|
27 |
+
overflow-y: auto;
|
28 |
+
border: 1px solid #ddd;
|
29 |
+
padding: 10px;
|
30 |
+
background-color: #f9f9f9;
|
31 |
+
margin-bottom: 10px;
|
32 |
+
border-radius: 5px;
|
33 |
+
}
|
34 |
+
.message {
|
35 |
+
margin: 10px 0;
|
36 |
+
padding: 10px;
|
37 |
+
border-radius: 5px;
|
38 |
+
max-width: 70%;
|
39 |
+
word-wrap: break-word;
|
40 |
+
}
|
41 |
+
.user-message {
|
42 |
+
background-color: #e1f5fe;
|
43 |
+
align-self: flex-end;
|
44 |
+
margin-left: auto;
|
45 |
+
}
|
46 |
+
.bot-message {
|
47 |
+
background-color: #f1f1f1;
|
48 |
+
align-self: flex-start;
|
49 |
+
margin-right: auto;
|
50 |
+
}
|
51 |
+
.input-area {
|
52 |
+
display: flex;
|
53 |
+
gap: 10px;
|
54 |
+
}
|
55 |
+
.input-text {
|
56 |
+
flex: 1;
|
57 |
+
padding: 10px;
|
58 |
+
border-radius: 5px;
|
59 |
+
border: 1px solid #ccc;
|
60 |
+
}
|
61 |
+
.send-btn {
|
62 |
+
padding: 10px 20px;
|
63 |
+
background-color: #4CAF50;
|
64 |
+
color: white;
|
65 |
+
border: none;
|
66 |
+
border-radius: 5px;
|
67 |
+
}
|
68 |
+
.send-btn:hover {
|
69 |
+
background-color: #45a049;
|
70 |
+
}
|
71 |
+
</style>
|
72 |
+
""", unsafe_allow_html=True)
|
73 |
+
|
74 |
+
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
75 |
+
st.markdown("## 🤖 አማርኛ ጤና ቻትቦት", unsafe_allow_html=True)
|
76 |
+
st.markdown("ስለ ወሊድና የአባላዘር በሽታ ጥያቄ አሎት? እባክዎ ያቀርቡ።", unsafe_allow_html=True)
|
77 |
+
st.markdown('<div class="chat-box" id="chat-box">', unsafe_allow_html=True)
|
78 |
+
|
79 |
+
# Use session state to track messages
|
80 |
+
if "messages" not in st.session_state:
|
81 |
+
st.session_state.messages = []
|
82 |
+
|
83 |
+
for msg in st.session_state.messages:
|
84 |
+
css_class = "user-message" if msg["sender"] == "user" else "bot-message"
|
85 |
+
st.markdown(f'<div class="message {css_class}">{msg["text"]}</div>', unsafe_allow_html=True)
|
86 |
+
|
87 |
+
st.markdown('</div>', unsafe_allow_html=True) # Close chat-box
|
88 |
+
|
89 |
+
# Input area
|
90 |
+
with st.form(key="chat_form"):
|
91 |
+
user_input = st.text_input("💬 ጥያቄዎን ያስገቡ:", key="input")
|
92 |
+
submit = st.form_submit_button("መልስ አውጣ")
|
93 |
+
|
94 |
+
if submit and user_input:
|
95 |
+
st.session_state.messages.append({"sender": "user", "text": user_input})
|
96 |
+
response = bot.get_answer(user_input)
|
97 |
+
|
98 |
+
if response == "__OUT_OF_SCOPE__":
|
99 |
+
response = "ይቅርታ፣ ይህንን ጥያቄ ማስተዋል አልቻልኩም። እባክዎ በሌላ መንገድ ይሞክሩ።"
|
100 |
+
|
101 |
+
st.session_state.messages.append({"sender": "bot", "text": response})
|
102 |
|
103 |
+
st.markdown('</div>', unsafe_allow_html=True) # Close chat-container
|
|
|
|
|
|
|
|
|
|
|
|
|
|