Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,69 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import torch
|
3 |
-
from
|
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 |
response = generate_response(user_input)
|
47 |
-
st.
|
|
|
48 |
else:
|
49 |
-
st.
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
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")
|
14 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("adi2606/Menstrual-Health-Awareness-Chatbot").to("cpu")
|
15 |
+
return tokenizer, 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()
|
30 |
+
st.markdown(
|
31 |
+
f"""
|
32 |
+
<style>
|
33 |
+
.stApp {{
|
34 |
+
background-image: url("data:image/png;base64,{encoded_string}");
|
35 |
+
background-size: cover;
|
36 |
+
}}
|
37 |
+
</style>
|
38 |
+
""",
|
39 |
+
unsafe_allow_html=True
|
40 |
+
)
|
41 |
+
|
42 |
+
|
43 |
+
set_background("background.jpg")
|
44 |
+
|
45 |
+
|
46 |
+
banner = Image.open("banner.png")
|
47 |
+
st.image(banner, use_column_width=True)
|
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..."):
|
61 |
response = generate_response(user_input)
|
62 |
+
st.success("✅ Here's what I found:")
|
63 |
+
st.markdown(f"**💬 Chatbot:** {response}")
|
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)
|