Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,198 +8,137 @@ import requests
|
|
8 |
from bs4 import BeautifulSoup
|
9 |
|
10 |
|
11 |
-
|
12 |
-
# os.environ['OLLAMA_HOST'] = '0.0.0.0:11434'
|
13 |
-
# os.environ['OLLAMA_ORIGINS'] = '*'
|
14 |
-
# print("Starting Ollama server...")
|
15 |
-
# try:
|
16 |
-
# subprocess.Popen(["ollama", "serve"])
|
17 |
-
# print("Ollama server started.")
|
18 |
-
# except Exception as e:
|
19 |
-
# print(f"Failed to start Ollama server: {e}")
|
20 |
-
|
21 |
-
# ollama_thread = threading.Thread(target=ollama)
|
22 |
-
# ollama_thread.start()
|
23 |
-
|
24 |
-
# model = 'llama3'
|
25 |
-
|
26 |
-
# def chat(messages):
|
27 |
-
# r = requests.post(
|
28 |
-
# "http://0.0.0.0:11434/api/chat",
|
29 |
-
# json={"model": model, "messages": messages, "stream": True},
|
30 |
-
# )
|
31 |
-
# r.raise_for_status()
|
32 |
-
# output = ""
|
33 |
-
# for line in r.iter_lines():
|
34 |
-
# body = json.loads(line)
|
35 |
-
# if "error" in body:
|
36 |
-
# raise Exception(body["error"])
|
37 |
-
# if body.get("done") is False:
|
38 |
-
# message = body.get("message", "")
|
39 |
-
# content = message.get("content", "")
|
40 |
-
# output += content
|
41 |
-
# print(content, end="", flush=True)
|
42 |
-
# if body.get("done", False):
|
43 |
-
# message["content"] = output
|
44 |
-
# return message
|
45 |
|
46 |
st.set_page_config(page_title="Affirmations", page_icon=":muscle:", layout="wide")
|
47 |
|
48 |
-
|
49 |
-
|
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 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
#
|
104 |
-
#
|
105 |
-
#
|
106 |
-
#
|
107 |
-
#
|
108 |
-
#
|
109 |
-
#
|
110 |
-
#
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
#
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
|
131 |
-
|
132 |
-
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
#
|
151 |
|
152 |
-
|
153 |
-
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
# llm = Ollama(model="llama3")
|
176 |
-
|
177 |
-
# 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
|
178 |
-
# 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
|
179 |
-
# do it more for feeling better, reduce resting heart rate, overall feeling fitter little bit everyday.\n
|
180 |
-
# 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
|
181 |
-
# Try to include taylor swift song lyrics in few places not forcefully but relevant to the overall content. \n
|
182 |
-
# I don\'t want output to use exactly these words i have written so that it does not feel fake or forceful.\n
|
183 |
-
# The structure should be conversational like taylor swift talking to me about my life and pets and not bullet points or third person.'''
|
184 |
-
|
185 |
-
# import os
|
186 |
-
# response = llm.invoke(prompt)
|
187 |
-
|
188 |
-
# st.markdown(response)
|
189 |
-
|
190 |
-
from langchain_community.llms import Ollama
|
191 |
-
|
192 |
-
# Initialize the Ollama model
|
193 |
-
llm = Ollama(model="llama3")
|
194 |
-
|
195 |
-
# Define your prompt
|
196 |
-
prompt = '''tell me a joke.'''
|
197 |
-
|
198 |
-
# Invoke the model with your prompt
|
199 |
-
response = llm.invoke(prompt)
|
200 |
-
|
201 |
-
# Display the response in your Streamlit app
|
202 |
-
st.markdown(response)
|
203 |
|
204 |
|
205 |
|
|
|
8 |
from bs4 import BeautifulSoup
|
9 |
|
10 |
|
11 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
st.set_page_config(page_title="Affirmations", page_icon=":muscle:", layout="wide")
|
14 |
|
15 |
+
st.markdown(
|
16 |
+
"""
|
17 |
+
<style>
|
18 |
+
.stApp {
|
19 |
+
background-color: #e9e5d9;
|
20 |
+
}
|
21 |
+
.title {
|
22 |
+
font-size: 36px;
|
23 |
+
font-weight: bold;
|
24 |
+
text-align: center;
|
25 |
+
margin-bottom: 20px;
|
26 |
+
}
|
27 |
+
.image-container {
|
28 |
+
display: flex;
|
29 |
+
justify-content: center;
|
30 |
+
margin-bottom: 20px;
|
31 |
+
}
|
32 |
+
.affirmation-box {
|
33 |
+
background-color: #ffffff;
|
34 |
+
padding: 20px;
|
35 |
+
border-radius: 10px;
|
36 |
+
margin-top: 20px;
|
37 |
+
text-align: center;
|
38 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
39 |
+
}
|
40 |
+
.affirmation-text {
|
41 |
+
font-family: 'Helvetica', sans-serif;
|
42 |
+
font-size: 18px;
|
43 |
+
color: #333333;
|
44 |
+
}
|
45 |
+
.stButton button {
|
46 |
+
background-color: #ff0000;
|
47 |
+
color: #ffffff;
|
48 |
+
font-size: 16px;
|
49 |
+
padding: 10px 20px;
|
50 |
+
border-radius: 5px;
|
51 |
+
margin-top: 20px;
|
52 |
+
width: 100%;
|
53 |
+
}
|
54 |
+
</style>
|
55 |
+
""",
|
56 |
+
unsafe_allow_html=True
|
57 |
+
)
|
58 |
+
|
59 |
+
col1, col2 = st.columns(2)
|
60 |
+
|
61 |
+
st.title("Taylor Swift's Gym Affirmations")
|
62 |
+
|
63 |
+
with col2:
|
64 |
+
st.image("https://www.rollingstone.com/wp-content/uploads/2023/05/GettyImages-1482443875.jpeg?w=1581&h=1054&crop=1")
|
65 |
+
|
66 |
+
with col1:
|
67 |
+
st.image("taylor_1.jpg")
|
68 |
+
|
69 |
+
if st.button("Generate Affirmation", key="generate_affirmation"):
|
70 |
+
# 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.
|
71 |
+
# In few days i see no gains and get irritated and give up. This time around i have decided to take it slow and
|
72 |
+
# do it more for feeling better, reduce resting heart rate, overall feeling fitter little bit everyday.
|
73 |
+
# 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.
|
74 |
+
# Try to include taylor swift song lyrics in few places not forcefully but relevant to the overall content.
|
75 |
+
# 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.
|
76 |
+
# The structure is basically conversational like taylor swift talking to me about my life and pets and not bullet points.
|
77 |
+
# """
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
def get_astrology_sign(birth_date):
|
82 |
+
# Zodiac signs divided by the date ranges
|
83 |
+
zodiac_dates = [
|
84 |
+
((1, 20), (2, 18), "11"),
|
85 |
+
((2, 19), (3, 20), "12"),
|
86 |
+
((3, 21), (4, 19), "1"),
|
87 |
+
((4, 20), (5, 20), "2"),
|
88 |
+
((5, 21), (6, 20), "3"),
|
89 |
+
((6, 21), (7, 22), "4"),
|
90 |
+
((7, 23), (8, 22), "5"),
|
91 |
+
((8, 23), (9, 22), "6"),
|
92 |
+
((9, 23), (10, 22), "7"),
|
93 |
+
((10, 23), (11, 21), "8"),
|
94 |
+
((11, 22), (12, 21), "9"),
|
95 |
+
((12, 22), (1, 19), "10")
|
96 |
+
]
|
97 |
|
98 |
+
month = birth_date.month
|
99 |
+
day = birth_date.day
|
100 |
|
101 |
+
for start, end, sign in zodiac_dates:
|
102 |
+
if (month == start[0] and day >= start[1]) or (month == end[0] and day <= end[1]):
|
103 |
+
return sign
|
104 |
+
return "Unknown"
|
105 |
|
106 |
|
107 |
+
def get_horoscope(zodiac_sign):
|
108 |
+
day = 'tomorrow'
|
109 |
+
url = (
|
110 |
+
"https://www.horoscope.com/us/horoscopes/general/"
|
111 |
+
f"horoscope-general-daily-{day}.aspx?sign={zodiac_sign}"
|
112 |
+
)
|
113 |
+
soup = BeautifulSoup(requests.get(url).content, "html.parser")
|
114 |
+
horoscope_text = soup.find("div", class_="main-horoscope").p.text
|
115 |
+
return horoscope_text
|
116 |
+
|
117 |
+
# Cancer
|
118 |
|
119 |
+
owner_sign = "4"
|
120 |
+
horoscope_text = get_horoscope(owner_sign)
|
121 |
|
122 |
+
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
|
123 |
+
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
|
124 |
+
do it more for feeling better, reduce resting heart rate, overall feeling fitter little bit everyday.\n
|
125 |
+
Here\'s my horoscope information for Today {}\n\n
|
126 |
+
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
|
127 |
+
Try to include taylor swift song lyrics in few places not forcefully but relevant to the overall content. \n
|
128 |
+
I don\'t want output to use exactly these words i have written so that it does not feel fake or forceful.\n
|
129 |
+
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)
|
130 |
+
|
131 |
+
|
132 |
+
messages = [{"role": "user", "content": prompt}]
|
133 |
+
response = chat(messages)
|
134 |
+
affirmation = response["content"]
|
135 |
+
with col1:
|
136 |
+
st.markdown(f'<div class="affirmation-box"><p class="horoscope-text">{horoscope_text}</p></div>', unsafe_allow_html=True)
|
137 |
+
with col2:
|
138 |
+
st.markdown(f'<div class="affirmation-box"><p class="affirmation-text">{affirmation}</p></div>', unsafe_allow_html=True)
|
139 |
+
|
140 |
+
|
141 |
+
groq_api_key = os.getenv['groq_api_token']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
|
144 |
|