tay-gym-dup / app.py
phildunphy14's picture
Update app.py
8b5b8d2 verified
raw
history blame
5.36 kB
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
)
col1, col2 = st.columns(2)
st.title("Taylor Swift's Gym 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 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
I don\'t want output to use exactly these words i have written so that it does not feel fake or forceful.\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)
# 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)