Spaces:
Running
Running
File size: 10,238 Bytes
f66f428 2fe5495 7157e78 3870a72 b36c6b5 3870a72 f66f428 3b70932 f66f428 3b70932 f66f428 3b70932 d99df65 f66f428 34119ef 31c48e5 f66f428 34119ef f66f428 34119ef f66f428 34119ef f66f428 34119ef f66f428 3870a72 b36c6b5 3870a72 80620d3 f66f428 ed3a947 f66f428 30ec7be 3870a72 f66f428 cb7065e f66f428 94b1746 8bcd009 94b1746 749da3e 94b1746 8489214 94b1746 0e7be9f c257f00 0e7be9f 16e4359 fa00338 16e4359 fa00338 16e4359 fa00338 16e4359 fa00338 16e4359 0e7be9f f66f428 cb7065e 80620d3 3b70932 f66f428 ed3a947 f66f428 ed3a947 f66f428 22282fb c796355 cb7065e f66f428 ed3a947 a90bbf4 cb7065e cef42ef 1df47ed 22282fb cef42ef 22282fb 18e3721 73b3892 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 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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
import streamlit as st
import time
import requests
from bs4 import BeautifulSoup
from datetime import date
import openai
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import requests
import json
from groq import Groq
import os
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, consider that as a predicting next week's scenarios.
If you find any event or scenarios mentioned in this week's horoscope and that event is not mentioned in today's horoscope, consider that for predicting tommorow's scenarios.
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 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 for Next Week's Prediction and Tommorow's Prediction.
Add a section of Couple Compatibility based on the moon signs of the couple, use your own knowledge and intelligence to deduce it.
Use BOLD headlines for all sections using MARKDOWN (**bold**).
Use bullets for details for all sections.
Add EMOJI for headlines to look interesting.
"""
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("div", class_="daily-horo text-center")
today=elements[0].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_="monthly-content")
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))
mday=article_block[0].text.strip()
return(mday)
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_="daily-horo text-center")
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))
wday=article_block[0].text.strip()
return(wday)
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
client = Groq()
client = Groq(api_key = os.getenv("GROQ_API_KEY"))
chatresponse = client.chat.completions.create(
model="deepseek-r1-distill-llama-70b",
messages=[
{"role": "system", "content": "You are a Horoscope Analyser. Think step by step. Answer in details with professional and dramatic 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.6,
stop=None,
stream=False
)
time.sleep(1)
prediction = chatresponse.choices[0].message.content
return prediction
def send_email(email,msg,stdate):
# Your Gmail credentials
sender_email = "[email protected]"
sender_password = "ibxccfsdcyzeittm"
# Recipient email address
receiver_email = email
message = MIMEMultipart("alternative")
message["Subject"] = "Horoscope Insights of " + stdate
message["From"] = sender_email
message["To"] = receiver_email
text = msg
part1 = MIMEText(text, "plain")
message.attach(part1)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender_email, sender_password)
server.sendmail(sender_email, receiver_email, message.as_string())
server.quit()
st.success("Email sent successfully!")
#yagmail
def send_yagmail(email,msg,stdate):
import yagmail
#receiver = email
#body = "Hello there from Yagmail HF"
#filename = "document.pdf"
sender_email = "[email protected]"
sender_password = "ibxccfsdcyzeittm"
yag = yagmail.SMTP(sender_email,sender_password)
yag.send(
to=email,
subject="Horoscope Insights of " + stdate,
contents=msg
#attachments=filename,
)
st.success("Yagmail sent successfully!")
def send_brevomail(email,msg,stdate):
url = 'https://api.brevo.com/v3/smtp/email'
headers = {
'accept': 'application/json',
'api-key': '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',
'content-type': 'application/json'
}
sender_email = "[email protected]"
receiver_email = email
subject = "Your Horoscope for " + stdate
body = "<html><head></head><body><p>Hello, here is your today's hororscope in short...</p>"+msg+"</p></body></html>"
data = {
"sender": {
"name": "Einstein AI",
"email": sender_email
},
"to": [
{
"email": receiver_email
}
],
"subject": subject,
"htmlContent": body
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
st.success("Email sent successfully!")
#print(response.text)
else:
st.error(f"Error {response.status_code}: {response.text}")
except requests.exceptions.HTTPError as errh:
st.error(f"HTTP Error: {errh}")
except requests.exceptions.ConnectionError as errc:
st.error(f"Error Connecting: {errc}")
except requests.exceptions.Timeout as errt:
st.error(f"Timeout Error: {errt}")
except requests.exceptions.RequestException as err:
st.error(f"An unexpected error occurred: {err}")
def main():
st.set_page_config(
page_title="Horoscope Insights",
page_icon="♏",
layout="wide"
)
st.title("Couple's Horoscope Insights")
st.markdown('Based on **Moon Signs** and **Vedic Astrology**. 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 Husband's Moon Sign", signs)
with col2:
female_sign = st.selectbox("Choose 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")
pred = []
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 + " | **Husband's Moon Sign**: " + m_sign + " | **Wife's Moon Sign**: " + f_sign)
title = "Today's is: " + strtime + " | Husband's Moon Sign: " + m_sign + " | Wife's Moon Sign: " + f_sign
#st.success("Insight generated!")
pred.append(prediction)
st.markdown(prediction)
#st.text(prediction)
email = st.text_input("Enter email address", "")
if st.button("Send Email"):
remail=email.strip()
msg = ' '.join(map(str, pred))
if msg == '' :
st.error("Message Body is Null")
else:
send_brevomail(remail,msg,strtime)
time.sleep(2)
st.success("Have a Great Day !")
if __name__ == '__main__':
main() |