arpit13 commited on
Commit
79f91c5
·
verified ·
1 Parent(s): 0efe4b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -11
app.py CHANGED
@@ -13,15 +13,15 @@ def fetch_astrology_data(endpoint, dob, tob, lat, lon, tz):
13
  if data.get("status") == 200 and "response" in data:
14
  return data["response"]
15
  else:
16
- return "Invalid response from API."
17
  else:
18
- return f"Error fetching data: {response.status_code}"
19
 
20
  # Function to check dasha
21
  def check_dasha(dasha_type, name, dob, tob, lat, lon, tz):
22
  response = fetch_astrology_data(f"dashas/{dasha_type}", dob, tob, lat, lon, tz)
23
  if isinstance(response, str):
24
- return response
25
 
26
  # Extracting Mahadasha and its order details
27
  mahadasha = response.get("mahadasha", [])
@@ -50,7 +50,33 @@ def check_dasha(dasha_type, name, dob, tob, lat, lon, tz):
50
 
51
  readable_response += "\n**Astrological Insights:** Based on your Mahadasha periods, you can predict the influences of each planet during your life."
52
 
53
- return readable_response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  # Gradio UI with improvements
56
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
@@ -68,16 +94,16 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
68
 
69
  result = gr.Markdown()
70
 
71
- def create_button(label, dasha_type, fn):
72
- return gr.Button(label, variant="primary").click(fn, inputs=[gr.State(dasha_type), name, dob, tob, lat, lon, tz], outputs=result)
73
 
74
  gr.Markdown("## 🌟 Dosha Analysis")
75
  with gr.Row():
76
- create_button("Mangal Dosh", "mangal-dosh", check_dasha)
77
- create_button("Kaalsarp Dosh", "kaalsarp-dosh", check_dasha)
78
- create_button("Manglik Dosh", "manglik-dosh", check_dasha)
79
- create_button("Pitra Dosh", "pitra-dosh", check_dasha)
80
- create_button("Papasamaya", "papasamaya", check_dasha)
81
 
82
  gr.Markdown("## 🔮 Dasha Analysis")
83
  with gr.Row():
 
13
  if data.get("status") == 200 and "response" in data:
14
  return data["response"]
15
  else:
16
+ return f"Invalid response from API: {data.get('message', 'No message provided')}"
17
  else:
18
+ return f"Error fetching data: {response.status_code} - {response.text}"
19
 
20
  # Function to check dasha
21
  def check_dasha(dasha_type, name, dob, tob, lat, lon, tz):
22
  response = fetch_astrology_data(f"dashas/{dasha_type}", dob, tob, lat, lon, tz)
23
  if isinstance(response, str):
24
+ return gr.Markdown(response)
25
 
26
  # Extracting Mahadasha and its order details
27
  mahadasha = response.get("mahadasha", [])
 
50
 
51
  readable_response += "\n**Astrological Insights:** Based on your Mahadasha periods, you can predict the influences of each planet during your life."
52
 
53
+ return gr.Markdown(readable_response)
54
+
55
+ # Function to check dosha
56
+ def check_dosha(dosha_type, name, dob, tob, lat, lon, tz):
57
+ response = fetch_astrology_data(f"dosha/{dosha_type}", dob, tob, lat, lon, tz)
58
+ if isinstance(response, str):
59
+ return gr.Markdown(response)
60
+
61
+ factors = response.get("factors", {})
62
+ dosha_present = response.get("is_dosha_present", False)
63
+ bot_response = response.get("bot_response", "No information available")
64
+ score = response.get("score", "N/A")
65
+
66
+ readable_response = f"""
67
+ ### {dosha_type.replace('-', ' ').title()} Analysis for {name}
68
+
69
+ **Dosha Presence:** {'Yes' if dosha_present else 'No'}
70
+ **Score:** {score}%
71
+
72
+ **Detailed Analysis:**
73
+ - **Moon Influence:** {factors.get('moon', 'Not mentioned')}
74
+ - **Saturn Influence:** {factors.get('saturn', 'Not mentioned')}
75
+ - **Rahu Influence:** {factors.get('rahu', 'Not mentioned')}
76
+
77
+ **Astrological Suggestion:** {bot_response}
78
+ """
79
+ return gr.Markdown(readable_response)
80
 
81
  # Gradio UI with improvements
82
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
94
 
95
  result = gr.Markdown()
96
 
97
+ def create_button(label, dosha_type, fn):
98
+ return gr.Button(label, variant="primary").click(fn, inputs=[gr.State(dosha_type), name, dob, tob, lat, lon, tz], outputs=result)
99
 
100
  gr.Markdown("## 🌟 Dosha Analysis")
101
  with gr.Row():
102
+ create_button("Mangal Dosh", "mangal-dosh", check_dosha)
103
+ create_button("Kaalsarp Dosh", "kaalsarp-dosh", check_dosha)
104
+ create_button("Manglik Dosh", "manglik-dosh", check_dosha)
105
+ create_button("Pitra Dosh", "pitra-dosh", check_dosha)
106
+ create_button("Papasamaya", "papasamaya", check_dosha)
107
 
108
  gr.Markdown("## 🔮 Dasha Analysis")
109
  with gr.Row():