arpit13 commited on
Commit
5fc7221
·
verified ·
1 Parent(s): d796ca3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -1,8 +1,22 @@
1
  import gradio as gr
2
  import requests
 
3
 
4
  API_KEY = "d6cf6f2e-301e-5f63-a988-b0a3aefd0896"
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # Function to fetch astrology data
7
  def fetch_astrology_data(endpoint, dob, tob, lat, lon, tz):
8
  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"
@@ -18,7 +32,11 @@ def fetch_astrology_data(endpoint, dob, tob, lat, lon, tz):
18
  return f"Error fetching data: {response.status_code} - {response.text}"
19
 
20
  # Function to check Dosha
21
- def check_dosha(dosha_type, name, dob, tob, lat, lon, tz):
 
 
 
 
22
  response = fetch_astrology_data(f"dosha/{dosha_type}", dob, tob, lat, lon, tz)
23
  if isinstance(response, str):
24
  return gr.Markdown(response)
@@ -46,7 +64,11 @@ def check_dosha(dosha_type, name, dob, tob, lat, lon, tz):
46
  return gr.Markdown(readable_response)
47
 
48
  # Function to check Dasha
49
- def check_dasha(dasha_type, name, dob, tob, lat, lon, tz):
 
 
 
 
50
  response = fetch_astrology_data(f"dashas/{dasha_type}", dob, tob, lat, lon, tz)
51
  if isinstance(response, str):
52
  return gr.Markdown(response)
@@ -70,7 +92,7 @@ def check_dasha(dasha_type, name, dob, tob, lat, lon, tz):
70
 
71
  return gr.Markdown(readable_response)
72
 
73
- # Gradio UI with improvements
74
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
75
  gr.Markdown("# 🪐 Astrology Checker - Find Your Dosha & Dasha 🪐")
76
 
@@ -80,14 +102,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
80
  tob = gr.Textbox(label="Time of Birth (HH:MM)", placeholder="11:40")
81
 
82
  with gr.Row():
83
- lat = gr.Number(label="Latitude", value=11)
84
- lon = gr.Number(label="Longitude", value=77)
85
  tz = gr.Number(label="Timezone (e.g., 5.5 for India)", value=5.5)
86
 
87
  result = gr.Markdown()
88
 
89
  def create_button(label, dosha_type, fn):
90
- return gr.Button(label, variant="primary").click(fn, inputs=[gr.State(dosha_type), name, dob, tob, lat, lon, tz], outputs=result)
91
 
92
  gr.Markdown("## 🌟 Dosha Analysis")
93
  with gr.Row():
@@ -103,14 +124,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
103
  create_button("Mahadasha Predictions", "maha-dasha-predictions", check_dasha)
104
  create_button("Antardasha", "antar-dasha", check_dasha)
105
  create_button("Char Dasha Current", "char-dasha-current", check_dasha)
106
- create_button("Char Dasha Main", "char-dasha-main", check_dasha)
107
- create_button("Char Dasha Sub", "char-dasha-sub", check_dasha)
108
- create_button("Current Mahadasha Full", "current-mahadasha-full", check_dasha)
109
- create_button("Current Mahadasha", "current-mahadasha", check_dasha)
110
- create_button("Paryantar Dasha", "paryantar-dasha", check_dasha)
111
- create_button("Specific Dasha", "specific-sub-dasha", check_dasha)
112
- create_button("Yogini Dasha Main", "yogini-dasha-main", check_dasha)
113
- create_button("Yogini Dasha Sub", "yogini-dasha-sub", check_dasha)
114
 
115
  gr.Markdown("### 🔍 Enter your details above and click the relevant button to analyze your astrology report!")
116
 
 
1
  import gradio as gr
2
  import requests
3
+ from geopy.geocoders import Nominatim
4
 
5
  API_KEY = "d6cf6f2e-301e-5f63-a988-b0a3aefd0896"
6
 
7
+ # Initialize Geolocator
8
+ geolocator = Nominatim(user_agent="astrology_checker")
9
+
10
+ # Function to fetch latitude and longitude based on location
11
+ def get_lat_lon(location):
12
+ location_info = geolocator.geocode(location)
13
+ if location_info:
14
+ lat = location_info.latitude
15
+ lon = location_info.longitude
16
+ return lat, lon
17
+ else:
18
+ return None, None
19
+
20
  # Function to fetch astrology data
21
  def fetch_astrology_data(endpoint, dob, tob, lat, lon, tz):
22
  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"
 
32
  return f"Error fetching data: {response.status_code} - {response.text}"
33
 
34
  # Function to check Dosha
35
+ def check_dosha(dosha_type, name, dob, tob, location, tz):
36
+ lat, lon = get_lat_lon(location)
37
+ if lat is None or lon is None:
38
+ return gr.Markdown("Location not found. Please check the location and try again.")
39
+
40
  response = fetch_astrology_data(f"dosha/{dosha_type}", dob, tob, lat, lon, tz)
41
  if isinstance(response, str):
42
  return gr.Markdown(response)
 
64
  return gr.Markdown(readable_response)
65
 
66
  # Function to check Dasha
67
+ def check_dasha(dasha_type, name, dob, tob, location, tz):
68
+ lat, lon = get_lat_lon(location)
69
+ if lat is None or lon is None:
70
+ return gr.Markdown("Location not found. Please check the location and try again.")
71
+
72
  response = fetch_astrology_data(f"dashas/{dasha_type}", dob, tob, lat, lon, tz)
73
  if isinstance(response, str):
74
  return gr.Markdown(response)
 
92
 
93
  return gr.Markdown(readable_response)
94
 
95
+ # Gradio UI with location input for latitude/longitude
96
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
97
  gr.Markdown("# 🪐 Astrology Checker - Find Your Dosha & Dasha 🪐")
98
 
 
102
  tob = gr.Textbox(label="Time of Birth (HH:MM)", placeholder="11:40")
103
 
104
  with gr.Row():
105
+ location = gr.Textbox(label="Location (City or Address)", placeholder="Enter your city or address")
 
106
  tz = gr.Number(label="Timezone (e.g., 5.5 for India)", value=5.5)
107
 
108
  result = gr.Markdown()
109
 
110
  def create_button(label, dosha_type, fn):
111
+ return gr.Button(label, variant="primary").click(fn, inputs=[dosha_type, name, dob, tob, location, tz], outputs=result)
112
 
113
  gr.Markdown("## 🌟 Dosha Analysis")
114
  with gr.Row():
 
124
  create_button("Mahadasha Predictions", "maha-dasha-predictions", check_dasha)
125
  create_button("Antardasha", "antar-dasha", check_dasha)
126
  create_button("Char Dasha Current", "char-dasha-current", check_dasha)
 
 
 
 
 
 
 
 
127
 
128
  gr.Markdown("### 🔍 Enter your details above and click the relevant button to analyze your astrology report!")
129