Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,9 @@ import torch
|
|
4 |
from PIL import Image
|
5 |
import base64
|
6 |
|
7 |
-
|
8 |
st.set_page_config(page_title="Menstrual Health Chatbot 💬", layout="centered")
|
9 |
|
10 |
-
|
11 |
@st.cache_resource
|
12 |
def load_model():
|
13 |
tokenizer = AutoTokenizer.from_pretrained("adi2606/Menstrual-Health-Awareness-Chatbot")
|
@@ -16,14 +15,14 @@ def load_model():
|
|
16 |
|
17 |
tokenizer, model = load_model()
|
18 |
|
19 |
-
|
20 |
def generate_response(input_text):
|
21 |
inputs = tokenizer(input_text, return_tensors="pt")
|
22 |
outputs = model.generate(**inputs, max_length=128)
|
23 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
return response
|
25 |
|
26 |
-
|
27 |
def set_background(image_path):
|
28 |
with open(image_path, "rb") as f:
|
29 |
encoded_string = base64.b64encode(f.read()).decode()
|
@@ -40,21 +39,28 @@ def set_background(image_path):
|
|
40 |
)
|
41 |
|
42 |
|
43 |
-
set_background("background.jpg")
|
44 |
|
45 |
|
46 |
-
banner = Image.open("banner.png")
|
47 |
-
st.image(banner,
|
48 |
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
st.markdown("<h1 style='text-align: center;'>🩸 Menstrual Health Awareness Chatbot 💬</h1>", unsafe_allow_html=True)
|
51 |
st.markdown("<h4 style='text-align: center;'>Ask anything about periods, PMS, hygiene, and more!</h4>", unsafe_allow_html=True)
|
52 |
|
53 |
-
|
54 |
st.markdown("### 🤔 Your Question")
|
55 |
user_input = st.text_input("", placeholder="E.g., What are the symptoms of PMS?")
|
56 |
|
57 |
-
|
58 |
if st.button("🚀 Ask"):
|
59 |
if user_input.strip():
|
60 |
with st.spinner("Generating a helpful response..."):
|
@@ -64,6 +70,5 @@ if st.button("🚀 Ask"):
|
|
64 |
else:
|
65 |
st.warning("⚠️ Please enter a question to get started.")
|
66 |
|
67 |
-
|
68 |
st.markdown("---")
|
69 |
st.markdown("<small style='color: gray;'>Made with ❤️ to spread awareness.</small>", unsafe_allow_html=True)
|
|
|
4 |
from PIL import Image
|
5 |
import base64
|
6 |
|
|
|
7 |
st.set_page_config(page_title="Menstrual Health Chatbot 💬", layout="centered")
|
8 |
|
9 |
+
# Load model
|
10 |
@st.cache_resource
|
11 |
def load_model():
|
12 |
tokenizer = AutoTokenizer.from_pretrained("adi2606/Menstrual-Health-Awareness-Chatbot")
|
|
|
15 |
|
16 |
tokenizer, model = load_model()
|
17 |
|
18 |
+
# Generate response
|
19 |
def generate_response(input_text):
|
20 |
inputs = tokenizer(input_text, return_tensors="pt")
|
21 |
outputs = model.generate(**inputs, max_length=128)
|
22 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
return response
|
24 |
|
25 |
+
# Background image
|
26 |
def set_background(image_path):
|
27 |
with open(image_path, "rb") as f:
|
28 |
encoded_string = base64.b64encode(f.read()).decode()
|
|
|
39 |
)
|
40 |
|
41 |
|
42 |
+
set_background("background.jpg")
|
43 |
|
44 |
|
45 |
+
banner = Image.open("banner.png")
|
46 |
+
st.image(banner, width=100)
|
47 |
|
48 |
|
49 |
+
st.markdown("""
|
50 |
+
<style>
|
51 |
+
h1, h4, .stMarkdown p, .stTextInput label, .css-1d391kg {
|
52 |
+
color: #111111 !important;
|
53 |
+
}
|
54 |
+
</style>
|
55 |
+
""", unsafe_allow_html=True)
|
56 |
+
|
57 |
+
# App content
|
58 |
st.markdown("<h1 style='text-align: center;'>🩸 Menstrual Health Awareness Chatbot 💬</h1>", unsafe_allow_html=True)
|
59 |
st.markdown("<h4 style='text-align: center;'>Ask anything about periods, PMS, hygiene, and more!</h4>", unsafe_allow_html=True)
|
60 |
|
|
|
61 |
st.markdown("### 🤔 Your Question")
|
62 |
user_input = st.text_input("", placeholder="E.g., What are the symptoms of PMS?")
|
63 |
|
|
|
64 |
if st.button("🚀 Ask"):
|
65 |
if user_input.strip():
|
66 |
with st.spinner("Generating a helpful response..."):
|
|
|
70 |
else:
|
71 |
st.warning("⚠️ Please enter a question to get started.")
|
72 |
|
|
|
73 |
st.markdown("---")
|
74 |
st.markdown("<small style='color: gray;'>Made with ❤️ to spread awareness.</small>", unsafe_allow_html=True)
|