import streamlit as st import requests import json import os import threading import subprocess import requests from bs4 import BeautifulSoup def ollama(): os.environ['OLLAMA_HOST'] = '0.0.0.0:11434' os.environ['OLLAMA_ORIGINS'] = '*' subprocess.Popen(["ollama", "serve"]) ollama_thread = threading.Thread(target=ollama) ollama_thread.start() model = 'llama3' def chat(messages): r = requests.post( "http://0.0.0.0:11434/api/chat", json={"model": model, "messages": messages, "stream": True}, ) r.raise_for_status() output = "" for line in r.iter_lines(): body = json.loads(line) if "error" in body: raise Exception(body["error"]) if body.get("done") is False: message = body.get("message", "") content = message.get("content", "") output += content print(content, end="", flush=True) if body.get("done", False): message["content"] = output return message st.set_page_config(page_title="Affirmations", page_icon=":muscle:", layout="wide") st.markdown( """ """, 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") if st.button("Generate Affirmation", key="generate_affirmation"): # 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. # In few days i see no gains and get irritated and give up. This time around i have decided to take it slow and # do it more for feeling better, reduce resting heart rate, overall feeling fitter little bit everyday. # Your job is to give me positive affirmations like taylor swift would talk to me in the theme i described of taking it slow and doing it more for happiness and feeling fit. # Try to include taylor swift song lyrics in few places not forcefully but relevant to the overall content. # Important is i am giving all this as context, i don't want output to use any of the words i have written so that it feel fake or forceful. # The structure is basically conversational like taylor swift talking to me about my life and pets and not bullet points. # """ 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 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 fewn lines about my horoscope 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.'''.format(horoscope_text) messages = [{"role": "user", "content": prompt}] response = chat(messages) affirmation = response["content"] with col1: st.markdown(f'

{horoscope_text}

', unsafe_allow_html=True) with col2: st.markdown(f'

{affirmation}

', unsafe_allow_html=True)