phildunphy14 commited on
Commit
ba53b4e
·
verified ·
1 Parent(s): e7b1c32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -183
app.py CHANGED
@@ -8,198 +8,137 @@ import requests
8
  from bs4 import BeautifulSoup
9
 
10
 
11
- # def ollama():
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
- # st.markdown(
49
- # """
50
- # <style>
51
- # .stApp {
52
- # background-color: #e9e5d9;
53
- # }
54
- # .title {
55
- # font-size: 36px;
56
- # font-weight: bold;
57
- # text-align: center;
58
- # margin-bottom: 20px;
59
- # }
60
- # .image-container {
61
- # display: flex;
62
- # justify-content: center;
63
- # margin-bottom: 20px;
64
- # }
65
- # .affirmation-box {
66
- # background-color: #ffffff;
67
- # padding: 20px;
68
- # border-radius: 10px;
69
- # margin-top: 20px;
70
- # text-align: center;
71
- # box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
72
- # }
73
- # .affirmation-text {
74
- # font-family: 'Helvetica', sans-serif;
75
- # font-size: 18px;
76
- # color: #333333;
77
- # }
78
- # .stButton button {
79
- # background-color: #ff0000;
80
- # color: #ffffff;
81
- # font-size: 16px;
82
- # padding: 10px 20px;
83
- # border-radius: 5px;
84
- # margin-top: 20px;
85
- # width: 100%;
86
- # }
87
- # </style>
88
- # """,
89
- # unsafe_allow_html=True
90
- # )
91
-
92
- # col1, col2 = st.columns(2)
93
-
94
- # st.title("Taylor Swift's Gym Affirmations")
95
-
96
- # with col2:
97
- # st.image("https://www.rollingstone.com/wp-content/uploads/2023/05/GettyImages-1482443875.jpeg?w=1581&h=1054&crop=1")
98
-
99
- # with col1:
100
- # st.image("taylor_1.jpg")
101
-
102
- # if st.button("Generate Affirmation", key="generate_affirmation"):
103
- # # 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.
104
- # # In few days i see no gains and get irritated and give up. This time around i have decided to take it slow and
105
- # # do it more for feeling better, reduce resting heart rate, overall feeling fitter little bit everyday.
106
- # # 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.
107
- # # Try to include taylor swift song lyrics in few places not forcefully but relevant to the overall content.
108
- # # 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.
109
- # # The structure is basically conversational like taylor swift talking to me about my life and pets and not bullet points.
110
- # # """
111
-
112
-
113
-
114
- # def get_astrology_sign(birth_date):
115
- # # Zodiac signs divided by the date ranges
116
- # zodiac_dates = [
117
- # ((1, 20), (2, 18), "11"),
118
- # ((2, 19), (3, 20), "12"),
119
- # ((3, 21), (4, 19), "1"),
120
- # ((4, 20), (5, 20), "2"),
121
- # ((5, 21), (6, 20), "3"),
122
- # ((6, 21), (7, 22), "4"),
123
- # ((7, 23), (8, 22), "5"),
124
- # ((8, 23), (9, 22), "6"),
125
- # ((9, 23), (10, 22), "7"),
126
- # ((10, 23), (11, 21), "8"),
127
- # ((11, 22), (12, 21), "9"),
128
- # ((12, 22), (1, 19), "10")
129
- # ]
130
 
131
- # month = birth_date.month
132
- # day = birth_date.day
133
 
134
- # for start, end, sign in zodiac_dates:
135
- # if (month == start[0] and day >= start[1]) or (month == end[0] and day <= end[1]):
136
- # return sign
137
- # return "Unknown"
138
 
139
 
140
- # def get_horoscope(zodiac_sign):
141
- # day = 'tomorrow'
142
- # url = (
143
- # "https://www.horoscope.com/us/horoscopes/general/"
144
- # f"horoscope-general-daily-{day}.aspx?sign={zodiac_sign}"
145
- # )
146
- # soup = BeautifulSoup(requests.get(url).content, "html.parser")
147
- # horoscope_text = soup.find("div", class_="main-horoscope").p.text
148
- # return horoscope_text
149
-
150
- # # Cancer
151
 
152
- # owner_sign = "4"
153
- # horoscope_text = get_horoscope(owner_sign)
154
 
155
- # 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
156
- # 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
157
- # do it more for feeling better, reduce resting heart rate, overall feeling fitter little bit everyday.\n
158
- # Here\'s my horoscope information for Today {}\n\n
159
- # 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
160
- # Try to include taylor swift song lyrics in few places not forcefully but relevant to the overall content. \n
161
- # I don\'t want output to use exactly these words i have written so that it does not feel fake or forceful.\n
162
- # 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)
163
-
164
-
165
- # messages = [{"role": "user", "content": prompt}]
166
- # response = chat(messages)
167
- # affirmation = response["content"]
168
- # with col1:
169
- # st.markdown(f'<div class="affirmation-box"><p class="horoscope-text">{horoscope_text}</p></div>', unsafe_allow_html=True)
170
- # with col2:
171
- # st.markdown(f'<div class="affirmation-box"><p class="affirmation-text">{affirmation}</p></div>', unsafe_allow_html=True)
172
-
173
-
174
- # from langchain_community.llms import Ollama
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