azeus commited on
Commit
768b9e4
·
1 Parent(s): 78e8f26

removed ephem

Browse files
Files changed (1) hide show
  1. app.py +69 -106
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  import pandas as pd
3
  from datetime import datetime
4
- import ephem
5
  import pytz
6
  from transformers import pipeline
7
  import math
@@ -27,56 +26,32 @@ except Exception as e:
27
  st.stop()
28
 
29
 
30
- def calculate_planetary_positions(birth_date, birth_time, timezone):
31
- """Calculate planetary positions at the time of birth."""
32
- # Create datetime object
33
- date_time = datetime.combine(birth_date, birth_time)
34
- tz = pytz.timezone(timezone)
35
- date_time = tz.localize(date_time)
36
-
37
- # Convert to UTC for ephem calculations
38
- date_time_utc = date_time.astimezone(pytz.UTC)
39
-
40
- # Initialize ephem date
41
- ephem_date = ephem.Date(date_time_utc)
42
-
43
- # Dictionary to store planetary positions
44
- positions = {}
45
-
46
- # Calculate positions for each planet
47
- planets = {
48
- 'Sun': ephem.Sun(),
49
- 'Moon': ephem.Moon(),
50
- 'Mercury': ephem.Mercury(),
51
- 'Venus': ephem.Venus(),
52
- 'Mars': ephem.Mars(),
53
- 'Jupiter': ephem.Jupiter(),
54
- 'Saturn': ephem.Saturn(),
55
- 'Uranus': ephem.Uranus(),
56
- 'Neptune': ephem.Neptune(),
57
- 'Pluto': ephem.Pluto()
58
- }
59
-
60
- for name, planet in planets.items():
61
- planet.compute(ephem_date)
62
- # Convert position to degrees
63
- position_deg = math.degrees(planet.hlong)
64
- # Normalize to 0-360 degrees
65
- position_deg = position_deg % 360
66
- positions[name] = position_deg
67
-
68
- return positions
69
-
70
-
71
- def get_zodiac_sign(longitude):
72
- """Convert longitude to zodiac sign."""
73
- signs = [
74
- "Aries", "Taurus", "Gemini", "Cancer",
75
- "Leo", "Virgo", "Libra", "Scorpio",
76
- "Sagittarius", "Capricorn", "Aquarius", "Pisces"
77
- ]
78
- sign_index = int(longitude / 30)
79
- return signs[sign_index]
80
 
81
 
82
  def get_element(sign):
@@ -90,44 +65,38 @@ def get_element(sign):
90
  return elements.get(sign, "Unknown")
91
 
92
 
93
- def generate_prediction(planetary_positions):
94
- """Generate daily prediction based on planetary positions."""
95
- # Create a prompt based on planetary positions and elements
96
- prompt = "Astrological reading based on planetary positions:\n"
97
-
98
- # Analyze dominant elements
99
- elements_count = {"Fire": 0, "Earth": 0, "Air": 0, "Water": 0}
100
-
101
- for planet, position in planetary_positions.items():
102
- sign = get_zodiac_sign(position)
103
- element = get_element(sign)
104
- elements_count[element] += 1
105
- prompt += f"{planet} in {sign} ({element})\n"
106
 
107
- # Find dominant element
108
- dominant_element = max(elements_count.items(), key=lambda x: x[1])[0]
109
- prompt += f"\nDominant element: {dominant_element}\n"
110
 
111
- # Calculate major aspects
112
- aspects = []
113
- planets = list(planetary_positions.items())
114
- for i, (planet1, pos1) in enumerate(planets):
115
- for planet2, pos2 in planets[i + 1:]:
116
- angle = abs(pos1 - pos2) % 360
117
- if abs(angle - 120) < 8: # Trine
118
- aspects.append(f"Harmonious trine between {planet1} and {planet2}")
119
- elif abs(angle - 90) < 8: # Square
120
- aspects.append(f"Challenging square between {planet1} and {planet2}")
121
- elif abs(angle - 180) < 8: # Opposition
122
- aspects.append(f"Dynamic opposition between {planet1} and {planet2}")
123
 
124
- if aspects:
125
- prompt += "\nSignificant aspects:\n" + "\n".join(aspects)
 
 
 
 
126
 
127
- prompt += "\nBased on these positions, today's prediction: "
 
128
 
129
  try:
130
- # Generate prediction using the model
131
  prediction = generator(
132
  prompt,
133
  max_length=200,
@@ -135,9 +104,7 @@ def generate_prediction(planetary_positions):
135
  temperature=0.7
136
  )[0]['generated_text']
137
 
138
- # Clean up the prediction
139
- prediction = prediction.split("today's prediction: ")[-1].strip()
140
- return prediction
141
  except Exception as e:
142
  return "Unable to generate prediction at this time. Please try again later."
143
 
@@ -167,30 +134,26 @@ timezone = st.selectbox(
167
  )
168
 
169
  if st.button("Get Prediction"):
170
- with st.spinner("Calculating planetary positions and generating prediction..."):
171
  try:
172
- # Calculate planetary positions
173
- positions = calculate_planetary_positions(birth_date, birth_time, timezone)
174
-
175
- # Display planetary positions
176
- st.subheader("Planetary Positions at Birth")
177
- planet_data = []
178
- for planet, position in positions.items():
179
- sign = get_zodiac_sign(position)
180
- element = get_element(sign)
181
- planet_data.append({
182
- "Planet": planet,
183
- "Sign": sign,
184
- "Element": element,
185
- "Degrees": f"{position:.2f}°"
186
- })
187
-
188
- df = pd.DataFrame(planet_data)
189
- st.table(df)
190
 
191
  # Generate and display prediction
192
  st.subheader("Your Daily Prediction")
193
- prediction = generate_prediction(positions)
194
  st.write(prediction)
195
 
196
  # Add disclaimer
 
1
  import streamlit as st
2
  import pandas as pd
3
  from datetime import datetime
 
4
  import pytz
5
  from transformers import pipeline
6
  import math
 
26
  st.stop()
27
 
28
 
29
+ def calculate_zodiac_sign(month, day):
30
+ """Calculate zodiac sign based on birth date."""
31
+ if (month == 3 and day >= 21) or (month == 4 and day <= 19):
32
+ return "Aries"
33
+ elif (month == 4 and day >= 20) or (month == 5 and day <= 20):
34
+ return "Taurus"
35
+ elif (month == 5 and day >= 21) or (month == 6 and day <= 20):
36
+ return "Gemini"
37
+ elif (month == 6 and day >= 21) or (month == 7 and day <= 22):
38
+ return "Cancer"
39
+ elif (month == 7 and day >= 23) or (month == 8 and day <= 22):
40
+ return "Leo"
41
+ elif (month == 8 and day >= 23) or (month == 9 and day <= 22):
42
+ return "Virgo"
43
+ elif (month == 9 and day >= 23) or (month == 10 and day <= 22):
44
+ return "Libra"
45
+ elif (month == 10 and day >= 23) or (month == 11 and day <= 21):
46
+ return "Scorpio"
47
+ elif (month == 11 and day >= 22) or (month == 12 and day <= 21):
48
+ return "Sagittarius"
49
+ elif (month == 12 and day >= 22) or (month == 1 and day <= 19):
50
+ return "Capricorn"
51
+ elif (month == 1 and day >= 20) or (month == 2 and day <= 18):
52
+ return "Aquarius"
53
+ else:
54
+ return "Pisces"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
 
57
  def get_element(sign):
 
65
  return elements.get(sign, "Unknown")
66
 
67
 
68
+ def calculate_nakshatra(birth_date):
69
+ """Calculate Nakshatra based on birth date (simplified calculation)."""
70
+ nakshatras = [
71
+ "Ashwini", "Bharani", "Krittika", "Rohini", "Mrigashira", "Ardra",
72
+ "Punarvasu", "Pushya", "Ashlesha", "Magha", "Purva Phalguni",
73
+ "Uttara Phalguni", "Hasta", "Chitra", "Swati", "Vishakha", "Anuradha",
74
+ "Jyeshtha", "Mula", "Purva Ashadha", "Uttara Ashadha", "Shravana",
75
+ "Dhanishta", "Shatabhisha", "Purva Bhadrapada", "Uttara Bhadrapada", "Revati"
76
+ ]
77
+ # Simplified calculation based on birth date
78
+ day_of_year = birth_date.timetuple().tm_yday
79
+ nakshatra_index = (day_of_year * 27) // 365
80
+ return nakshatras[nakshatra_index]
81
 
 
 
 
82
 
83
+ def generate_prediction(birth_date, birth_time, timezone):
84
+ """Generate prediction based on astrological factors."""
85
+ zodiac_sign = calculate_zodiac_sign(birth_date.month, birth_date.day)
86
+ element = get_element(zodiac_sign)
87
+ nakshatra = calculate_nakshatra(birth_date)
 
 
 
 
 
 
 
88
 
89
+ prompt = f"""
90
+ Astrological reading for a person born under:
91
+ - Zodiac Sign: {zodiac_sign}
92
+ - Element: {element}
93
+ - Nakshatra: {nakshatra}
94
+ - Birth Time: {birth_time.strftime('%H:%M')}
95
 
96
+ Based on these positions, today's prediction:
97
+ """
98
 
99
  try:
 
100
  prediction = generator(
101
  prompt,
102
  max_length=200,
 
104
  temperature=0.7
105
  )[0]['generated_text']
106
 
107
+ return prediction.split("today's prediction: ")[-1].strip()
 
 
108
  except Exception as e:
109
  return "Unable to generate prediction at this time. Please try again later."
110
 
 
134
  )
135
 
136
  if st.button("Get Prediction"):
137
+ with st.spinner("Calculating astrological factors and generating prediction..."):
138
  try:
139
+ # Display birth chart information
140
+ st.subheader("Your Astrological Profile")
141
+ zodiac_sign = calculate_zodiac_sign(birth_date.month, birth_date.day)
142
+ element = get_element(zodiac_sign)
143
+ nakshatra = calculate_nakshatra(birth_date)
144
+
145
+ profile_data = pd.DataFrame([{
146
+ "Zodiac Sign": zodiac_sign,
147
+ "Element": element,
148
+ "Nakshatra": nakshatra,
149
+ "Birth Time": birth_time.strftime("%H:%M")
150
+ }])
151
+
152
+ st.table(profile_data)
 
 
 
 
153
 
154
  # Generate and display prediction
155
  st.subheader("Your Daily Prediction")
156
+ prediction = generate_prediction(birth_date, birth_time, timezone)
157
  st.write(prediction)
158
 
159
  # Add disclaimer