arpit13 commited on
Commit
c6ebf38
·
verified ·
1 Parent(s): 44dc108

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -17
app.py CHANGED
@@ -1,27 +1,55 @@
1
  import gradio as gr
2
  import requests
3
 
4
- def check_mangal_dosh(name, dob, tob, lat, lon, tz):
5
- API_KEY = "d6cf6f2e-301e-5f63-a988-b0a3aefd0896"
6
- 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"
 
7
  response = requests.get(url)
8
 
9
  if response.status_code == 200:
10
  data = response.json()
11
- if data.get("status") == 200 and data.get("response"):
12
- factors = data["response"].get("factors", {})
13
- dosha_present = data["response"].get("is_dosha_present", False)
14
- bot_response = data["response"].get("bot_response", "No information available")
15
- score = data["response"].get("score", "N/A")
16
-
17
- return f"Mangal Dosh: {'Yes' if dosha_present else 'No'}\nScore: {score}%\n{bot_response}"
18
  else:
19
  return "Invalid response from API."
20
  else:
21
- return "Error fetching data."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  with gr.Blocks() as demo:
24
- gr.Markdown("## Mangal Dosh Checker")
25
 
26
  with gr.Row():
27
  name = gr.Textbox(label="Name")
@@ -33,9 +61,19 @@ with gr.Blocks() as demo:
33
  lon = gr.Number(label="Longitude")
34
  tz = gr.Number(label="Time Zone")
35
 
36
- submit_btn = gr.Button("Check")
37
- result = gr.Textbox()
38
 
39
- submit_btn.click(check_mangal_dosh, inputs=[name, dob, tob, lat, lon, tz], outputs=result)
40
-
41
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import requests
3
 
4
+ API_KEY = "d6cf6f2e-301e-5f63-a988-b0a3aefd0896"
5
+
6
+ def fetch_astrology_data(endpoint, dob, tob, lat, lon, tz):
7
+ 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"
8
  response = requests.get(url)
9
 
10
  if response.status_code == 200:
11
  data = response.json()
12
+ if data.get("status") == 200 and "response" in data:
13
+ return data["response"]
 
 
 
 
 
14
  else:
15
  return "Invalid response from API."
16
  else:
17
+ return f"Error fetching data: {response.status_code}"
18
+
19
+ def check_dosha(dosha_type, name, dob, tob, lat, lon, tz):
20
+ response = fetch_astrology_data(f"dosha/{dosha_type}", dob, tob, lat, lon, tz)
21
+ if isinstance(response, str):
22
+ return response
23
+
24
+ factors = response.get("factors", {})
25
+ dosha_present = response.get("is_dosha_present", False)
26
+ bot_response = response.get("bot_response", "No information available")
27
+ score = response.get("score", "N/A")
28
+
29
+ readable_response = f"""
30
+ **{dosha_type.replace('-', ' ').title()} Analysis for {name}:**
31
+
32
+ **Dosha Presence:** {'Yes' if dosha_present else 'No'}
33
+ **Score:** {score}%
34
+
35
+ **Detailed Analysis:**
36
+ - **Moon Influence:** {factors.get('moon', 'Not mentioned')}
37
+ - **Saturn Influence:** {factors.get('saturn', 'Not mentioned')}
38
+ - **Rahu Influence:** {factors.get('rahu', 'Not mentioned')}
39
+
40
+ **Astrological Suggestion:** {bot_response}
41
+ """
42
+ return readable_response
43
+
44
+ def check_dasha(dasha_type, name, dob, tob, lat, lon, tz):
45
+ response = fetch_astrology_data(f"dashas/{dasha_type}", dob, tob, lat, lon, tz)
46
+ if isinstance(response, str):
47
+ return response
48
+
49
+ return f"**{dasha_type.replace('-', ' ').title()} Analysis for {name}:**\n\n" + str(response)
50
 
51
  with gr.Blocks() as demo:
52
+ gr.Markdown("## Astrology Checker 🪐")
53
 
54
  with gr.Row():
55
  name = gr.Textbox(label="Name")
 
61
  lon = gr.Number(label="Longitude")
62
  tz = gr.Number(label="Time Zone")
63
 
64
+ result = gr.Markdown()
 
65
 
66
+ with gr.Row():
67
+ gr.Button("Mangal Dosh").click(check_dosha, inputs=["mangal-dosh", name, dob, tob, lat, lon, tz], outputs=result)
68
+ gr.Button("Kaalsarp Dosh").click(check_dosha, inputs=["kaalsarp-dosh", name, dob, tob, lat, lon, tz], outputs=result)
69
+ gr.Button("Manglik Dosh").click(check_dosha, inputs=["manglik-dosh", name, dob, tob, lat, lon, tz], outputs=result)
70
+ gr.Button("Pitra Dosh").click(check_dosha, inputs=["pitra-dosh", name, dob, tob, lat, lon, tz], outputs=result)
71
+ gr.Button("Papasamaya").click(check_dosha, inputs=["papasamaya", name, dob, tob, lat, lon, tz], outputs=result)
72
+
73
+ with gr.Row():
74
+ gr.Button("Mahadasha").click(check_dasha, inputs=["maha-dasha", name, dob, tob, lat, lon, tz], outputs=result)
75
+ gr.Button("Mahadasha Predictions").click(check_dasha, inputs=["maha-dasha-predictions", name, dob, tob, lat, lon, tz], outputs=result)
76
+ gr.Button("Antardasha").click(check_dasha, inputs=["antar-dasha", name, dob, tob, lat, lon, tz], outputs=result)
77
+ gr.Button("Char Dasha Current").click(check_dasha, inputs=["char-dasha-current", name, dob, tob, lat, lon, tz], outputs=result)
78
+
79
+ demo.launch()