EinsteinCoder commited on
Commit
f66f428
·
1 Parent(s): 2247716

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +136 -0
app.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import time
3
+ import requests
4
+ from bs4 import BeautifulSoup
5
+ from datetime import date
6
+ import openai
7
+
8
+ openai.api_key = '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'
9
+
10
+ template = """Shared with you the horoscopes of today, this week, and this month for a couple.
11
+ Your task is to analyse them provide insights to the couple from all the horoscopes.
12
+ If you find any event or scenarios mentioned in this month's horoscope and that event is not mentioned in this week's horoscope, then that might happen next week. Predict next week's scenarios in this manner.
13
+ If you find any event or scenarios mentioned in this week's horoscope and that event is not mentioned in today's horoscope, then that might happen tommorow. Predict tommorow's scenarios in this manner.
14
+ Add a section for Today's HoroScope Summary for Husband.
15
+ Add a section for Today's HoroScope Summary for Wife.
16
+ Add a section for Couple's HoroScope Insights For This Month.
17
+ Add a section for Next Week's Prediction and Tommorow's Prediction.
18
+ Add a section to aware the couple for any upcoming negative traits or events or scenarios.
19
+ Add a section to notify about all the Lucky Dates.
20
+ Add a section of Couple Compatibility based on the moon signs of the couple, use your own knowledge and intelligence to deduce it.
21
+ Use bullets and headlines for all sections.
22
+ Add emojis where-ever necessary to look interesting.
23
+ """
24
+
25
+ def get_daily_pred(url):
26
+ URL = url
27
+ headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246"}
28
+ r = requests.get(URL,headers=headers)
29
+ soup = BeautifulSoup(r.content, 'html.parser') # If this line causes an error, run 'pip install html5lib' or install html5lib
30
+ #print(soup.prettify())
31
+ elements = soup.find_all("p")
32
+ today=elements[1].text.strip()
33
+ return(today)
34
+
35
+ def get_monthly_pred(url):
36
+ URL = url
37
+ headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246"}
38
+ r = requests.get(URL,headers=headers)
39
+ soup = BeautifulSoup(r.content, 'html.parser') # If this line causes an error, run 'pip install html5lib' or install html5lib
40
+ #print(soup.prettify())
41
+ article_block =soup.find_all('div', class_="horoscope-sign-content-block")
42
+ data=[]
43
+ for articles in article_block:
44
+ br = articles.find_all('br')
45
+ for val in br:
46
+ br_val = val.text.strip()
47
+ data.append(br_val)
48
+ monthly = ' '.join(map(str, data))
49
+ return(monthly)
50
+
51
+ def get_weekly_pred(url):
52
+ URL = url
53
+ headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246"}
54
+ r = requests.get(URL,headers=headers)
55
+ soup = BeautifulSoup(r.content, 'html.parser') # If this line causes an error, run 'pip install html5lib' or install html5lib
56
+ #print(soup.prettify())
57
+ article_block =soup.find_all('div', class_="span-9 span-sm-9 span-xs-12 col m")
58
+ data=[]
59
+ for articles in article_block:
60
+ br = articles.find_all('br')
61
+ for val in br:
62
+ br_val = val.text.strip()
63
+ data.append(br_val)
64
+ weekly = ' '.join(map(str, data))
65
+ return(weekly)
66
+
67
+ def predict_horoscope(m_sign, f_sign,strtime,m_daily_pred,f_daily_pred,m_monthly_pred,f_monthly_pred,m_weekly_pred,f_weekly_pred):
68
+ # Add your horoscope prediction logic here
69
+ chatresponse = openai.ChatCompletion.create(
70
+ model="gpt-3.5-turbo",
71
+ messages=[
72
+ {"role": "system", "content": "You are a Horoscope Analyser. Think step by step. Answer in details with professional tone"},
73
+ {"role": "user", "content": template},
74
+ {"role": "user", "content": "Today's date is: " + strtime},
75
+ {"role": "user", "content": "Husband's Moon Sign: " + m_sign},
76
+ {"role": "user", "content": "Wife's Moon Sign: " + f_sign},
77
+ {"role": "user", "content": "Husband Daily Horoscope: " + m_daily_pred},
78
+ {"role": "user", "content": "Husband Weekly Horoscope: " + m_weekly_pred},
79
+ {"role": "user", "content": "Husband Monthly Horoscope: " + m_monthly_pred},
80
+ {"role": "user", "content": "Wife Daily Horoscope: " + f_daily_pred},
81
+ {"role": "user", "content": "Wife Weekly Horoscope: " + f_weekly_pred},
82
+ {"role": "user", "content": "Wife Monthly Horoscope: " + f_monthly_pred}
83
+ ],
84
+ temperature=0.7
85
+ )
86
+ time.sleep(3)
87
+ prediction = chatresponse.choices[0].message.content
88
+ return prediction
89
+
90
+ def main():
91
+ st.title("Couple's Horoscope Insights Using GenAI")
92
+
93
+ signs = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
94
+ "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]
95
+
96
+ col1, col2 = st.columns(2) # Create two columns
97
+
98
+ with col1:
99
+ male_sign = st.selectbox("Choose Male (Husband's) Moon Sign", signs)
100
+
101
+ with col2:
102
+ female_sign = st.selectbox("Choose Female (Wife's) Moon Sign", signs)
103
+
104
+ m_sign= male_sign
105
+ f_sign= female_sign
106
+
107
+ m_url_daily="https://www.indastro.com/horoscope/"+m_sign+"-daily-horoscope.html"
108
+ f_url_daily="https://www.indastro.com/horoscope/"+f_sign+"-daily-horoscope.html"
109
+
110
+ m_url_monthly="https://www.indastro.com/horoscope/"+m_sign+"-monthly-horoscope.html"
111
+ f_url_monthly="https://www.indastro.com/horoscope/"+f_sign+"-monthly-horoscope.html"
112
+
113
+ m_url_weekly="https://www.indastro.com/horoscope/weekly-horoscope/"+m_sign+".html"
114
+ f_url_weekly="https://www.indastro.com/horoscope/weekly-horoscope/"+f_sign+".html"
115
+
116
+ m_daily_pred = get_daily_pred(m_url_daily)
117
+ f_daily_pred = get_daily_pred(f_url_daily)
118
+
119
+ m_monthly_pred = get_monthly_pred(m_url_monthly)
120
+ f_monthly_pred = get_monthly_pred(f_url_monthly)
121
+
122
+ m_weekly_pred = get_weekly_pred(m_url_weekly)
123
+ f_weekly_pred = get_weekly_pred(f_url_weekly)
124
+
125
+ today = date.today()
126
+ strtime = today.strftime("%d-%B-%Y")
127
+
128
+
129
+ if st.button("Show"):
130
+ with st.spinner("Generating prediction..."):
131
+ prediction = predict_horoscope(m_sign, f_sign,strtime,m_daily_pred,f_daily_pred,m_monthly_pred,f_monthly_pred,m_weekly_pred,f_weekly_pred)
132
+ st.success("Prediction generated!")
133
+ st.write("Horoscope Prediction:", prediction)
134
+
135
+ if __name__ == '__main__':
136
+ main()