tay-gym-dup / app.py
phildunphy14's picture
Update app.py
af2ecb9 verified
import streamlit as st
import requests
import json
import os
import threading
import subprocess
import requests
from bs4 import BeautifulSoup
st.set_page_config(page_title="Affirmations", page_icon=":muscle:", layout="wide")
# st.markdown(
# """
# <style>
# .stApp {
# background-color: #e9e5d9;
# }
# .title {
# font-size: 36px;
# font-weight: bold;
# text-align: center;
# margin-bottom: 20px;
# }
# .image-container {
# display: flex;
# justify-content: center;
# margin-bottom: 20px;
# }
# .affirmation-box {
# background-color: #ffffff;
# padding: 20px;
# border-radius: 10px;
# margin-top: 20px;
# text-align: center;
# box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
# }
# .affirmation-text {
# font-family: 'Helvetica', sans-serif;
# font-size: 18px;
# color: #333333;
# }
# .stButton button {
# background-color: #ff0000;
# color: #ffffff;
# font-size: 16px;
# padding: 10px 20px;
# border-radius: 5px;
# margin-top: 20px;
# width: 100%;
# }
# </style>
# """,
# unsafe_allow_html=True
# )
st.markdown(
"""
<style>
:root {
color-scheme: light dark;
}
.stApp {
background-color: var(--background);
}
.title {
font-size: 36px;
font-weight: bold;
text-align: center;
margin-bottom: 20px;
color: var(--text);
}
.image-container {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.affirmation-box {
background-color: var(--box-background);
padding: 20px;
border-radius: 10px;
margin-top: 20px;
text-align: center;
box-shadow: var(--box-shadow);
}
.affirmation-text {
font-family: 'Helvetica', sans-serif;
font-size: 18px;
color: var(--text);
}
.stButton button {
background-color: var(--button-background);
color: var(--button-text);
font-size: 16px;
padding: 10px 20px;
border-radius: 5px;
margin-top: 20px;
width: 100%;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #333333;
--text: #ffffff;
--box-background: #424242;
--box-shadow: 0 2px 4px rgba(255, 255, 255, 0.1);
--button-background: #0084ff;
--button-text: #ffffff;
}
}
@media (prefers-color-scheme: light) {
:root {
--background: #e9e5d9;
--text: #333333;
--box-background: #ffffff;
--box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
--button-background: #ff0000;
--button-text: #ffffff;
}
}
</style>
""",
unsafe_allow_html=True
)
col1, col2 = st.columns(2)
st.title("Taylor Swift's Affirmations")
with col2:
st.image("https://www.rollingstone.com/wp-content/uploads/2023/05/GettyImages-1482443875.jpeg?w=1581&h=1054&crop=1")
with col1:
st.image("taylor_1.jpg")
context = st.text_input("Tell taylor about your day for her context")
groq_api_key = os.getenv('groq_api_token')
from groq import Groq
client = Groq(
api_key=groq_api_key,
)
def llama3_8b(prompt, temperature=0.0, input_print=True):
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": prompt,
}
],
model="llama3-8b-8192",
temperature=temperature,
)
return (chat_completion.choices[0].message.content)
def llama3_70b(prompt, temperature=0.0, input_print=True):
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": prompt,
}
],
model="llama3-70b-8192",
temperature=temperature,
)
return (chat_completion.choices[0].message.content)
if st.button("Generate Affirmation", key="generate_affirmation"):
def get_astrology_sign(birth_date):
# Zodiac signs divided by the date ranges
zodiac_dates = [
((1, 20), (2, 18), "11"),
((2, 19), (3, 20), "12"),
((3, 21), (4, 19), "1"),
((4, 20), (5, 20), "2"),
((5, 21), (6, 20), "3"),
((6, 21), (7, 22), "4"),
((7, 23), (8, 22), "5"),
((8, 23), (9, 22), "6"),
((9, 23), (10, 22), "7"),
((10, 23), (11, 21), "8"),
((11, 22), (12, 21), "9"),
((12, 22), (1, 19), "10")
]
month = birth_date.month
day = birth_date.day
for start, end, sign in zodiac_dates:
if (month == start[0] and day >= start[1]) or (month == end[0] and day <= end[1]):
return sign
return "Unknown"
def get_horoscope(zodiac_sign):
day = 'tomorrow'
url = (
"https://www.horoscope.com/us/horoscopes/general/"
f"horoscope-general-daily-{day}.aspx?sign={zodiac_sign}"
)
soup = BeautifulSoup(requests.get(url).content, "html.parser")
horoscope_text = soup.find("div", class_="main-horoscope").p.text
return horoscope_text
# Cancer
owner_sign = "4"
horoscope_text = get_horoscope(owner_sign)
# prompt = '''My name is aditi, i have 2 pets named Jamun and Misri and i do not like going to gym because i expect results too quickly\n
# In few days i see no gains and get irritated and give up. This time around i have decided to take it slow and \n
# do it more for feeling better, reduce resting heart rate, overall feeling fitter little bit everyday.\n
# Here\'s my horoscope information for Today {}\n\n
# I have also described how my day has been {}\n\n
# Taking all this above context , Your job is to give me positive affirmations like taylor swift would talk to me in the theme of starting with few lines about my life in general and then talk about my fitness goals.\n
# Try to include taylor swift song lyrics in few places not forcefully but relevant to the overall content. \n
# Do not repeat the same words i enter in context instead build it into the conversation\n
# The structure should be conversational like taylor swift talking to me about my life and pets and not bullet points or third person. Also do not include actions in itallic words, just keep it to conversations.'''.format(horoscope_text,context)
prompt = '''My name is Aditi, and I have two pets named Jamun and Misri. Lately, I've been trying to find the best ways to navigate my day-to-day life, taking into account my horoscope and current mood.
Today's horoscope for me is: {}
Here’s a brief about how my day has been or how I’m feeling: {}
I'm looking for some guidance in the style of Taylor Swift about my overall life and start of gym journey where i have decided to take it slow and do it more for feeling better, overall feeling fitter little bit everyday. Suggest some playlist songs (include atleast 1 taylor swift song) randomly everyday relevant to horoscope and how i feel.
Imagine Taylor chatting with me, using her song lyrics to provide insights and advice about handling daily challenges and emotions. The response should sound like a conversation directly from Taylor,
reflecting her unique tone and style. Please integrate her lyrics in a way that feels natural and relevant to the discussion,
avoiding any forced inclusion or repetitive language from my input. Keep the format purely conversational,
with no bullet points or third-person narrative, and not itallics to describe actions.'''.format(horoscope_text, context)
# messages = [{"role": "user", "content": prompt}]
# response = chat(messages)
# affirmation = response["content"]
output = llama3_70b(prompt)
with col1:
st.markdown(f'<div class="affirmation-box"><p class="horoscope-text">{horoscope_text}</p></div>', unsafe_allow_html=True)
with col2:
st.markdown(f'<div class="affirmation-box"><p class="affirmation-text">{output}</p></div>', unsafe_allow_html=True)