Spaces:
Sleeping
Sleeping
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 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 | |
) | |
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 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") | |
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) | |
#st.success("Insight generated!") | |
#st.markdown(prediction) | |
st.text(prediction) | |
if __name__ == '__main__': | |
main() |