cyclelist / app.py
memn's picture
Update app.py
3d51ea4 verified
Raw History Blame
5.6 kB
import streamlit as st
from transformers import pipeline
import PyPDF2
import datetime
# Initialize the Hugging Face text generation pipeline
model = pipeline('text-generation', model='distilgpt2')
# Load and parse the PDF file for the knowledge base
pdf_path = "/mnt/data/Einsteiger Guide Leben im Einklang mit dem weiblichen Zyklus.pdf"
pdf_reader = PyPDF2.PdfFileReader(pdf_path)
pdf_text = ""
for page_num in range(pdf_reader.numPages):
page = pdf_reader.getPage(page_num)
pdf_text += page.extract_text()
# Define the CSS style for the UI with a mobile-friendly design
st.markdown("""
<style>
body {
font-family: 'Satoshi', sans-serif;
background-color: white;
}
.main {
background-color: white;
}
.stButton>button {
background-color: #ff4d94;
color: white;
width: 100%;
}
.stTextInput>div>div>input {
background-color: #ff99c2;
color: white;
}
.stTextArea>div>textarea {
background-color: #ff99c2;
color: white;
}
.stSubheader, .stText, .stHeader, h1, h2 {
color: #b30047;
}
@media (max-width: 768px) {
.stApp {
padding: 1rem;
}
.stTextInput>div>div>input, .stTextArea>div>textarea {
width: 100%;
}
.stButton>button {
font-size: 1rem;
padding: 0.75rem 1.5rem;
}
.stHeader, .stSubheader {
font-size: 1.25rem;
}
.stText {
font-size: 1rem;
}
}
</style>
""", unsafe_allow_html=True)
# Set title and subtitle
st.title("Welcome to Your Menstrual Cycle Story")
st.subheader("Align with Your Body")
# Input fields for user parameters
days_menstruation = st.number_input("Days of Menstruation", min_value=1, max_value=10, step=1)
days_cycle = st.number_input("Days of Cycle", min_value=21, max_value=35, step=1)
last_period_start_date = st.date_input("Last Period Start Date")
mood_past_3_days = st.text_area("Mood of the Past 3 Days")
goals_next_3_months = st.text_area("Goals for the Next 3 Months")
# Function to determine the current cycle phase
def determine_cycle_phase(days_menstruation, days_cycle, last_period_start_date):
today = datetime.date.today()
cycle_day = (today - last_period_start_date).days % days_cycle
if cycle_day < days_menstruation:
return "Menstruation Phase (Winter)"
elif cycle_day < days_menstruation + (days_cycle - days_menstruation) // 2:
return "Follicular Phase (Spring)"
elif cycle_day < days_menstruation + (days_cycle - days_menstruation) // 2 + 1:
return "Ovulation Phase (Summer)"
else:
return "Luteal Phase (Autumn)"
# Submit button
if st.button("Generate Story"):
if days_menstruation and days_cycle and mood_past_3_days and goals_next_3_months and last_period_start_date:
# Determine current cycle phase
current_phase = determine_cycle_phase(days_menstruation, days_cycle, last_period_start_date)
# Fetch relevant information from the PDF
if "Menstruationsphase" in pdf_text and "Ernährung" in pdf_text:
phase_info = pdf_text.split("Menstruationsphase")[1].split("Ernährung")[0]
else:
phase_info = "I am sorry I am only an Assistant and I advise you to call an expert."
# Generate the story using Hugging Face's GPT-3
input_text = (f"Welcome to a journey of understanding your body. "
f"With {days_menstruation} days of menstruation in a cycle of {days_cycle} days, "
f"you've experienced {mood_past_3_days} in the past three days. "
f"For the next three months, your goals are {goals_next_3_months}. "
f"Currently, you are in the {current_phase}. Here is some information based on your current phase: {phase_info}. "
f"Let me guide you through this beautiful phase with a story.")
story = model(input_text, max_length=200, num_return_sequences=1)[0]['generated_text']
st.write(story)
else:
st.error("Please fill in all the fields.")
# Example knowledge base information
st.header("Menstrual Cycle Knowledge Base")
st.write("""
The menstrual cycle is a natural process that occurs in the female body to prepare for a potential pregnancy. It consists of several phases:
- **Menstrual Phase:** This is the phase where the uterine lining sheds, causing bleeding.
- **Follicular Phase:** The body prepares for ovulation by growing follicles in the ovaries.
- **Ovulation Phase:** An egg is released from the ovary, making it the most fertile phase.
- **Luteal Phase:** The body prepares for a possible pregnancy or the next menstrual cycle.
**Tips for Managing Different Phases:**
- **Menstrual Phase:** Rest and engage in gentle activities like reading or journaling.
- **Follicular Phase:** Plan new projects and gradually increase your activity.
- **Ovulation Phase:** Use your high energy for social and professional networking.
- **Luteal Phase:** Focus on completing tasks and integrate stress-reducing activities like yoga.
Remember, your body and cycle are unique. Embrace and understand your cycle to align better with your body's natural rhythms.
""")
st.header("Tools for Better Understanding")
st.write("""
Use apps like Flo or Clue to track your cycle, symptoms, and moods. These apps provide valuable insights and predictions to help you stay in tune with your body.
""")