Update app.py
Browse filesadding knowledge base
app.py
CHANGED
|
@@ -1,5 +1,18 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Define the CSS style for the UI with a mobile-friendly design
|
| 5 |
st.markdown("""
|
|
@@ -16,7 +29,11 @@ st.markdown("""
|
|
| 16 |
color: white;
|
| 17 |
width: 100%;
|
| 18 |
}
|
| 19 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
background-color: #ff99c2;
|
| 21 |
color: white;
|
| 22 |
}
|
|
@@ -27,7 +44,7 @@ st.markdown("""
|
|
| 27 |
.stApp {
|
| 28 |
padding: 1rem;
|
| 29 |
}
|
| 30 |
-
.
|
| 31 |
width: 100%;
|
| 32 |
}
|
| 33 |
.stButton>button {
|
|
@@ -45,62 +62,74 @@ st.markdown("""
|
|
| 45 |
""", unsafe_allow_html=True)
|
| 46 |
|
| 47 |
# Set title and subtitle
|
| 48 |
-
st.title("Menstrual Cycle")
|
| 49 |
-
st.subheader("
|
| 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 |
-
"emotionale_veränderungen": "Introspection, low energy, need for rest."
|
| 77 |
-
},
|
| 78 |
-
"Follicular Phase (Spring)": {
|
| 79 |
-
"beschreibung": "The body prepares for ovulation by growing follicles in the ovaries.",
|
| 80 |
-
"körperliche_veränderungen": "Increased energy, clearer skin, higher libido.",
|
| 81 |
-
"emotionale_veränderungen": "Optimism, creativity, motivation."
|
| 82 |
-
},
|
| 83 |
-
"Ovulation Phase (Summer)": {
|
| 84 |
-
"beschreibung": "The most fertile phase where an egg is released from the ovary.",
|
| 85 |
-
"körperliche_veränderungen": "Peak energy, heightened senses, possible mild cramps.",
|
| 86 |
-
"emotionale_veränderungen": "High self-confidence, sociability, sexual desire."
|
| 87 |
-
},
|
| 88 |
-
"Luteal Phase (Autumn)": {
|
| 89 |
-
"beschreibung": "The body prepares for a possible pregnancy or the next menstrual cycle.",
|
| 90 |
-
"körperliche_veränderungen": "Bloating, breast tenderness, cravings.",
|
| 91 |
-
"emotionale_veränderungen": "Irritability, mood swings, increased stress."
|
| 92 |
-
}
|
| 93 |
-
}
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
#
|
| 98 |
-
st.
|
| 99 |
-
st.write("
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
-
st.
|
| 105 |
-
|
| 106 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import PyPDF2
|
| 4 |
+
import datetime
|
| 5 |
+
|
| 6 |
+
# Initialize the Hugging Face text generation pipeline
|
| 7 |
+
model = pipeline('text-generation', model='gpt-3')
|
| 8 |
+
|
| 9 |
+
# Load and parse the PDF file for the knowledge base
|
| 10 |
+
pdf_path = "/mnt/data/Einsteiger Guide Leben im Einklang mit dem weiblichen Zyklus.pdf"
|
| 11 |
+
pdf_reader = PyPDF2.PdfFileReader(pdf_path)
|
| 12 |
+
pdf_text = ""
|
| 13 |
+
for page_num in range(pdf_reader.numPages):
|
| 14 |
+
page = pdf_reader.getPage(page_num)
|
| 15 |
+
pdf_text += page.extract_text()
|
| 16 |
|
| 17 |
# Define the CSS style for the UI with a mobile-friendly design
|
| 18 |
st.markdown("""
|
|
|
|
| 29 |
color: white;
|
| 30 |
width: 100%;
|
| 31 |
}
|
| 32 |
+
.stTextInput>div>div>input {
|
| 33 |
+
background-color: #ff99c2;
|
| 34 |
+
color: white;
|
| 35 |
+
}
|
| 36 |
+
.stTextArea>div>textarea {
|
| 37 |
background-color: #ff99c2;
|
| 38 |
color: white;
|
| 39 |
}
|
|
|
|
| 44 |
.stApp {
|
| 45 |
padding: 1rem;
|
| 46 |
}
|
| 47 |
+
.stTextInput>div>div>input, .stTextArea>div>textarea {
|
| 48 |
width: 100%;
|
| 49 |
}
|
| 50 |
.stButton>button {
|
|
|
|
| 62 |
""", unsafe_allow_html=True)
|
| 63 |
|
| 64 |
# Set title and subtitle
|
| 65 |
+
st.title("Welcome to Your Menstrual Cycle Story")
|
| 66 |
+
st.subheader("Align with Your Body")
|
| 67 |
|
| 68 |
+
# Input fields for user parameters
|
| 69 |
+
days_menstruation = st.number_input("Days of Menstruation", min_value=1, max_value=10, step=1)
|
| 70 |
+
days_cycle = st.number_input("Days of Cycle", min_value=21, max_value=35, step=1)
|
| 71 |
+
last_period_start_date = st.date_input("Last Period Start Date")
|
| 72 |
+
mood_past_3_days = st.text_area("Mood of the Past 3 Days")
|
| 73 |
+
goals_next_3_months = st.text_area("Goals for the Next 3 Months")
|
| 74 |
|
| 75 |
+
# Function to determine the current cycle phase
|
| 76 |
+
def determine_cycle_phase(days_menstruation, days_cycle, last_period_start_date):
|
| 77 |
+
today = datetime.date.today()
|
| 78 |
+
cycle_day = (today - last_period_start_date).days % days_cycle
|
| 79 |
|
| 80 |
+
if cycle_day < days_menstruation:
|
| 81 |
+
return "Menstruation Phase (Winter)"
|
| 82 |
+
elif cycle_day < days_menstruation + (days_cycle - days_menstruation) // 2:
|
| 83 |
+
return "Follicular Phase (Spring)"
|
| 84 |
+
elif cycle_day < days_menstruation + (days_cycle - days_menstruation) // 2 + 1:
|
| 85 |
+
return "Ovulation Phase (Summer)"
|
| 86 |
+
else:
|
| 87 |
+
return "Luteal Phase (Autumn)"
|
| 88 |
|
| 89 |
+
# Submit button
|
| 90 |
+
if st.button("Generate Story"):
|
| 91 |
+
if days_menstruation and days_cycle and mood_past_3_days and goals_next_3_months and last_period_start_date:
|
| 92 |
+
# Determine current cycle phase
|
| 93 |
+
current_phase = determine_cycle_phase(days_menstruation, days_cycle, last_period_start_date)
|
|
|
|
| 94 |
|
| 95 |
+
# Fetch relevant information from the PDF
|
| 96 |
+
if "Menstruationsphase" in pdf_text and "Ernährung" in pdf_text:
|
| 97 |
+
phase_info = pdf_text.split("Menstruationsphase")[1].split("Ernährung")[0]
|
| 98 |
+
else:
|
| 99 |
+
phase_info = "I am sorry I am only an Assistant and I advise you to call an expert."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
# Generate the story using Hugging Face's GPT-3
|
| 102 |
+
input_text = (f"Welcome to a journey of understanding your body. "
|
| 103 |
+
f"With {days_menstruation} days of menstruation in a cycle of {days_cycle} days, "
|
| 104 |
+
f"you've experienced {mood_past_3_days} in the past three days. "
|
| 105 |
+
f"For the next three months, your goals are {goals_next_3_months}. "
|
| 106 |
+
f"Currently, you are in the {current_phase}. Here is some information based on your current phase: {phase_info}. "
|
| 107 |
+
f"Let me guide you through this beautiful phase with a story.")
|
| 108 |
+
|
| 109 |
+
story = model(input_text, max_length=200, num_return_sequences=1)[0]['generated_text']
|
| 110 |
+
st.write(story)
|
| 111 |
+
else:
|
| 112 |
+
st.error("Please fill in all the fields.")
|
| 113 |
|
| 114 |
+
# Example knowledge base information
|
| 115 |
+
st.header("Menstrual Cycle Knowledge Base")
|
| 116 |
+
st.write("""
|
| 117 |
+
The menstrual cycle is a natural process that occurs in the female body to prepare for a potential pregnancy. It consists of several phases:
|
| 118 |
+
- **Menstrual Phase:** This is the phase where the uterine lining sheds, causing bleeding.
|
| 119 |
+
- **Follicular Phase:** The body prepares for ovulation by growing follicles in the ovaries.
|
| 120 |
+
- **Ovulation Phase:** An egg is released from the ovary, making it the most fertile phase.
|
| 121 |
+
- **Luteal Phase:** The body prepares for a possible pregnancy or the next menstrual cycle.
|
| 122 |
+
|
| 123 |
+
**Tips for Managing Different Phases:**
|
| 124 |
+
- **Menstrual Phase:** Rest and engage in gentle activities like reading or journaling.
|
| 125 |
+
- **Follicular Phase:** Plan new projects and gradually increase your activity.
|
| 126 |
+
- **Ovulation Phase:** Use your high energy for social and professional networking.
|
| 127 |
+
- **Luteal Phase:** Focus on completing tasks and integrate stress-reducing activities like yoga.
|
| 128 |
+
|
| 129 |
+
Remember, your body and cycle are unique. Embrace and understand your cycle to align better with your body's natural rhythms.
|
| 130 |
+
""")
|
| 131 |
|
| 132 |
+
st.header("Tools for Better Understanding")
|
| 133 |
+
st.write("""
|
| 134 |
+
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.
|
| 135 |
+
""")
|