Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
API_KEY = "d6cf6f2e-301e-5f63-a988-b0a3aefd0896" | |
# Function to fetch astrology data | |
def fetch_astrology_data(endpoint, dob, tob, lat, lon, tz): | |
url = f"https://api.vedicastroapi.com/v3-json/{endpoint}?dob={dob}&tob={tob}&lat={lat}&lon={lon}&tz={tz}&api_key={API_KEY}&lang=en" | |
response = requests.get(url) | |
if response.status_code == 200: | |
data = response.json() | |
if data.get("status") == 200 and "response" in data: | |
return data["response"] | |
else: | |
return f"Invalid response from API: {data.get('message', 'No message provided')}" | |
else: | |
return f"Error fetching data: {response.status_code} - {response.text}" | |
# Function to check Dosha | |
def check_dosha(dosha_type, name, dob, tob, lat, lon, tz): | |
response = fetch_astrology_data(f"dosha/{dosha_type}", dob, tob, lat, lon, tz) | |
if isinstance(response, str): | |
return gr.Markdown(response) | |
factors = response.get("factors", {}) | |
dosha_present = response.get("is_dosha_present", False) | |
bot_response = response.get("bot_response", "No information available") | |
score = response.get("score", "N/A") | |
readable_response = f""" | |
### {dosha_type.replace('-', ' ').title()} Analysis for {name} | |
**Dosha Presence:** {'Yes' if dosha_present else 'No'} | |
**Score:** {score}% | |
**Detailed Analysis:** | |
- **Moon Influence:** {factors.get('moon', 'Not mentioned')} | |
- **Saturn Influence:** {factors.get('saturn', 'Not mentioned')} | |
- **Rahu Influence:** {factors.get('rahu', 'Not mentioned')} | |
**Astrological Suggestion:** {bot_response} | |
""" | |
return gr.Markdown(readable_response) | |
# Function to check Dasha | |
def check_dasha(dasha_type, name, dob, tob, lat, lon, tz): | |
response = fetch_astrology_data(f"dashas/{dasha_type}", dob, tob, lat, lon, tz) | |
if isinstance(response, str): | |
return gr.Markdown(response) | |
# Extracting Mahadasha and its order details | |
mahadasha = response.get("mahadasha", []) | |
mahadasha_order = response.get("mahadasha_order", []) | |
dasha_start_date = response.get("dasha_start_date", "N/A") | |
dasha_remaining_at_birth = response.get("dasha_remaining_at_birth", "N/A") | |
# Format the dasha data to make it more readable | |
readable_response = f""" | |
### {dasha_type.replace('-', ' ').title()} Analysis for {name} | |
**Dasha Start Date:** {dasha_start_date} | |
**Remaining Dasha at Birth:** {dasha_remaining_at_birth} | |
## Mahadasha Sequence: | |
Here is the order of your Mahadasha periods: | |
""" | |
if len(mahadasha) == 0 or len(mahadasha_order) == 0: | |
readable_response += "**No Mahadasha data available.**" | |
else: | |
table = "| **Period** | **Planet** |\n|--------------|---------------|\n" | |
for i in range(len(mahadasha)): | |
if i < len(mahadasha_order): | |
period = mahadasha_order[i] | |
planet = mahadasha[i] | |
table += f"| {period} | {planet} |\n" | |
readable_response += table | |
if not mahadasha or not mahadasha_order: | |
readable_response += "\n## Astrological Insights: Data not available for the current period." | |
else: | |
readable_response += """ | |
## Astrological Insights: | |
Based on your Mahadasha periods, you can predict the influences of each planet during your life. | |
""" | |
return gr.Markdown(readable_response) | |
# Gradio UI with improvements | |
with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
gr.Markdown("# 🪐 Astrology Checker - Find Your Dosha & Dasha 🪐") | |
with gr.Row(): | |
name = gr.Textbox(label="Name", placeholder="Enter your name") | |
dob = gr.Textbox(label="DOB (DD/MM/YYYY)", placeholder="21/04/2021") | |
tob = gr.Textbox(label="Time of Birth (HH:MM)", placeholder="11:40") | |
with gr.Row(): | |
lat = gr.Number(label="Latitude", value=11) | |
lon = gr.Number(label="Longitude", value=77) | |
tz = gr.Number(label="Timezone (e.g., 5.5 for India)", value=5.5) | |
result = gr.Markdown() | |
def create_button(label, dosha_type, fn): | |
return gr.Button(label, variant="primary").click(fn, inputs=[gr.State(dosha_type), name, dob, tob, lat, lon, tz], outputs=result) | |
gr.Markdown("## 🌟 Dosha Analysis") | |
with gr.Row(): | |
create_button("Mangal Dosh", "mangal-dosh", check_dosha) | |
create_button("Kaalsarp Dosh", "kaalsarp-dosh", check_dosha) | |
create_button("Manglik Dosh", "manglik-dosh", check_dosha) | |
create_button("Pitra Dosh", "pitra-dosh", check_dosha) | |
create_button("Papasamaya", "papasamaya", check_dosha) | |
gr.Markdown("## 🔮 Dasha Analysis") | |
with gr.Row(): | |
create_button("Mahadasha", "maha-dasha", check_dasha) | |
create_button("Mahadasha Predictions", "maha-dasha-predictions", check_dasha) | |
create_button("Antardasha", "antar-dasha", check_dasha) | |
create_button("Char Dasha Current", "char-dasha-current", check_dasha) | |
gr.Markdown("### 🔍 Enter your details above and click the relevant button to analyze your astrology report!") | |
demo.launch() | |