File size: 6,753 Bytes
f66f428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
842c735
 
f66f428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb7065e
f66f428
cb7065e
f66f428
 
 
 
cb7065e
 
 
 
 
 
 
f66f428
a29b89a
f66f428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb7065e
 
f66f428
8f89c2d
cb7065e
a29b89a
f66f428
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
import streamlit as st
import time
import requests
from bs4 import BeautifulSoup
from datetime import date
import openai

openai.api_key = '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'

template = """Shared with you the horoscopes of today, this week, and this month for a couple.
Your task is to analyse them provide insights to the couple from all the horoscopes.
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.
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.
Add a section for Today's HoroScope Summary for Husband.
Add a section for Today's HoroScope Summary for Wife.
Add a section for Couple's HoroScope Insights For This Month.
Add a section for Next Week's Prediction and Tommorow's Prediction.
Add a section to aware the couple for any upcoming negative traits or events or scenarios. 
Add a section to notify about all the Lucky Dates. 
Add a section of Couple Compatibility based on the moon signs of the couple, use your own knowledge and intelligence to deduce it.
Use bullets and headlines for all sections.
Add emojis to look interesting.
Emphasize the keywords with BOLD letters using markdown.
"""

def get_daily_pred(url):
  URL = url
  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"}
  r = requests.get(URL,headers=headers)
  soup = BeautifulSoup(r.content, 'html.parser') # If this line causes an error, run 'pip install html5lib' or install html5lib
  #print(soup.prettify())
  elements = soup.find_all("p")
  today=elements[1].text.strip()
  return(today)

def get_monthly_pred(url):
  URL = url
  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"}
  r = requests.get(URL,headers=headers)
  soup = BeautifulSoup(r.content, 'html.parser') # If this line causes an error, run 'pip install html5lib' or install html5lib
  #print(soup.prettify())
  article_block =soup.find_all('div', class_="horoscope-sign-content-block")
  data=[]
  for articles in article_block:
    br = articles.find_all('br')
    for val in br:
       br_val = val.text.strip()
       data.append(br_val)
  monthly = ' '.join(map(str, data))
  return(monthly)

def get_weekly_pred(url):
    URL = url
    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"}
    r = requests.get(URL,headers=headers)
    soup = BeautifulSoup(r.content, 'html.parser') # If this line causes an error, run 'pip install html5lib' or install html5lib
    #print(soup.prettify())
    article_block =soup.find_all('div', class_="span-9 span-sm-9 span-xs-12 col m")
    data=[]
    for articles in article_block:
      br = articles.find_all('br')
      for val in br:
       br_val = val.text.strip()
       data.append(br_val)
    weekly = ' '.join(map(str, data))
    return(weekly)

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):
    # Add your horoscope prediction logic here
    chatresponse = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a Horoscope Analyser. Think step by step. Answer in details with professional tone"},        
        {"role": "user", "content": template},
        {"role": "user", "content": "Today's date is: " + strtime},
        {"role": "user", "content": "Husband's Moon Sign: " + m_sign},     
        {"role": "user", "content": "Wife's Moon Sign: " + f_sign},
        {"role": "user", "content": "Husband Daily Horoscope: " + m_daily_pred},
        {"role": "user", "content": "Husband Weekly Horoscope: " + m_weekly_pred},
        {"role": "user", "content": "Husband Monthly Horoscope: " + m_monthly_pred},
        {"role": "user", "content": "Wife Daily Horoscope: " + f_daily_pred},
        {"role": "user", "content": "Wife Weekly Horoscope: " + f_weekly_pred},
        {"role": "user", "content": "Wife Monthly Horoscope: " + f_monthly_pred}
    ],
    temperature=0
    )
    time.sleep(1)
    prediction = chatresponse.choices[0].message.content
    return prediction

def main():

    st.set_page_config(
       page_title="Horoscope Insights",
       page_icon="♏",
       layout="wide"
        )
    
    st.title("Couple's Horoscope Insights Using GenAI")
    st.markdown('Based on **Moon Signs**. Get your Moon Sign from here: https://instaastro.com/vedic-astrology/moon-sign-calculator/')

    signs = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", 
             "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]

    col1, col2 = st.columns(2)  # Create two columns

    with col1:
        male_sign = st.selectbox("Choose Male (Husband's) Moon Sign", signs)

    with col2:
        female_sign = st.selectbox("Choose Female (Wife's) Moon Sign", signs)
    
    m_sign= male_sign
    f_sign= female_sign
    
    m_url_daily="https://www.indastro.com/horoscope/"+m_sign+"-daily-horoscope.html"
    f_url_daily="https://www.indastro.com/horoscope/"+f_sign+"-daily-horoscope.html"

    m_url_monthly="https://www.indastro.com/horoscope/"+m_sign+"-monthly-horoscope.html"
    f_url_monthly="https://www.indastro.com/horoscope/"+f_sign+"-monthly-horoscope.html"

    m_url_weekly="https://www.indastro.com/horoscope/weekly-horoscope/"+m_sign+".html"
    f_url_weekly="https://www.indastro.com/horoscope/weekly-horoscope/"+f_sign+".html"
    
    m_daily_pred = get_daily_pred(m_url_daily)
    f_daily_pred = get_daily_pred(f_url_daily)

    m_monthly_pred = get_monthly_pred(m_url_monthly)
    f_monthly_pred = get_monthly_pred(f_url_monthly)

    m_weekly_pred = get_weekly_pred(m_url_weekly)
    f_weekly_pred = get_weekly_pred(f_url_weekly)

    today = date.today()
    strtime = today.strftime("%d-%B-%Y")


    if st.button("Show Insights"):
        with st.spinner("Generating Insights..."):
            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)
            st.info("**Today's is**: " + strtime + " | **Male (Husband's) Moon Sign**: " + m_sign + " | **Wife's Moon Sign**: " + f_sign)
            #st.success("Insight generated!")
            st.markdown(prediction)

if __name__ == '__main__':
    main()