Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
def check_mangal_dosh(name, dob, tob, lat, lon, tz, api_key): | |
url = f"https://api.vedicastroapi.com/v3-json/dosha/mangal-dosh?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 data.get("response"): | |
factors = data["response"].get("factors", {}) | |
dosha_present = data["response"].get("is_dosha_present", False) | |
bot_response = data["response"].get("bot_response", "No information available") | |
score = data["response"].get("score", "N/A") | |
readable_response = f""" | |
**Mangal Dosh 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 readable_response | |
else: | |
return "Invalid response from API. Please check input values." | |
else: | |
return f"Error fetching data: {response.status_code}" | |
with gr.Blocks() as demo: | |
gr.Markdown("# Mangal Dosh Checker 🪐") | |
gr.Markdown("Enter your details to check for Mangal Dosh:") | |
name = gr.Textbox(label="Name") | |
dob = gr.Textbox(label="Date of Birth (DD/MM/YYYY)") | |
tob = gr.Textbox(label="Time of Birth (HH:MM)") | |
lat = gr.Number(label="Latitude") | |
lon = gr.Number(label="Longitude") | |
tz = gr.Number(label="Time Zone (e.g., 5.5)") | |
api_key = gr.Textbox(label="API Key", type="password") | |
submit_btn = gr.Button("Check Mangal Dosh") | |
result = gr.Markdown() | |
submit_btn.click(check_mangal_dosh, inputs=[name, dob, tob, lat, lon, tz, api_key], outputs=result) | |
demo.launch() | |