cryogenic22 commited on
Commit
cf52217
·
verified ·
1 Parent(s): 07ed5b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +299 -25
app.py CHANGED
@@ -18,7 +18,7 @@ st.set_page_config(
18
  initial_sidebar_state="expanded"
19
  )
20
 
21
- # Custom CSS for a more modern look
22
  st.markdown("""
23
  <style>
24
  .stApp {
@@ -37,6 +37,9 @@ st.markdown("""
37
  padding: 0.5rem 1rem;
38
  border: none;
39
  }
 
 
 
40
  .chat-message {
41
  padding: 1.5rem;
42
  border-radius: 10px;
@@ -53,9 +56,213 @@ st.markdown("""
53
  margin-right: 20%;
54
  border-left: 4px solid #9F7AEA;
55
  }
 
 
 
 
 
 
 
56
  </style>
57
  """, unsafe_allow_html=True)
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  def init_session_state():
60
  """Initialize session state variables"""
61
  if 'birth_chart' not in st.session_state:
@@ -94,6 +301,51 @@ def get_location_details(location_name: str) -> Dict[str, Any]:
94
  except Exception as e:
95
  return {'error': f"Error finding location: {str(e)}"}
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  def main():
98
  st.title("🌟 AI Astrology Assistant")
99
 
@@ -125,9 +377,12 @@ def main():
125
  placeholder="City, Country"
126
  )
127
 
128
- submit = st.form_submit_button("Calculate Birth Chart")
 
 
 
129
 
130
- if submit:
131
  if not birth_place:
132
  st.error("Please enter your birth place.")
133
  else:
@@ -160,49 +415,68 @@ def main():
160
 
161
  # Display chart and analysis if available
162
  if st.session_state.birth_chart and 'error' not in st.session_state.birth_chart:
163
- tab1, tab2, tab3 = st.tabs(["Chart Visualization", "Technical Details", "AI Analysis"])
164
 
165
  with tab1:
166
- st.plotly_chart(
167
- create_chart_visualization(st.session_state.birth_chart),
168
- use_container_width=True
169
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  with tab2:
172
- st.subheader("Planetary Positions")
173
- for planet, data in st.session_state.birth_chart['planets'].items():
174
- if 'error' not in data:
175
- st.markdown(f"""
176
- <div style='background-color: white; padding: 1rem; border-radius: 8px; margin-bottom: 0.5rem;'>
177
- <strong>{planet}</strong>: {data['degrees']:.1f}° {data['sign']} in House {data.get('house', 'Unknown')}
178
- {' 🔄' if data.get('retrograde', False) else ''}
179
- </div>
180
- """, unsafe_allow_html=True)
181
-
182
  with tab3:
183
  if st.session_state.initial_analysis:
 
184
  st.markdown(st.session_state.initial_analysis)
185
 
186
  # Chat interface
 
187
  st.markdown("### 💬 Ask about your chart")
188
 
189
  # Suggested questions
190
  questions = [
191
- "What are the main themes in my chart?",
192
- "What are my career strengths?",
193
- "How does my chart influence relationships?",
194
- "What are my biggest challenges?",
195
- "What are my spiritual or creative gifts?"
 
 
 
 
 
196
  ]
197
 
198
  selected_question = st.selectbox(
199
  "Choose a question or type your own below:",
200
- [""] + questions
 
201
  )
202
 
203
  user_question = st.text_input(
204
  "Your question:",
205
- value=selected_question,
206
  key="user_input"
207
  )
208
 
 
18
  initial_sidebar_state="expanded"
19
  )
20
 
21
+ # Custom CSS for a modern look
22
  st.markdown("""
23
  <style>
24
  .stApp {
 
37
  padding: 0.5rem 1rem;
38
  border: none;
39
  }
40
+ .stButton > button:hover {
41
+ background-color: #553C9A;
42
+ }
43
  .chat-message {
44
  padding: 1.5rem;
45
  border-radius: 10px;
 
56
  margin-right: 20%;
57
  border-left: 4px solid #9F7AEA;
58
  }
59
+ .element-card {
60
+ background-color: white;
61
+ padding: 1rem;
62
+ border-radius: 8px;
63
+ margin-bottom: 0.5rem;
64
+ box-shadow: 0 2px 4px rgba(0,0,0,0.05);
65
+ }
66
  </style>
67
  """, unsafe_allow_html=True)
68
 
69
+ def create_chart_visualization(chart_data: Dict[str, Any]):
70
+ """Create a professional astrological chart visualization"""
71
+ fig = go.Figure()
72
+
73
+ # Define colors for zodiac signs (matching traditional colors)
74
+ zodiac_colors = {
75
+ 'Aries': '#e8fde8', # Light green
76
+ 'Taurus': '#fff9e6', # Light yellow
77
+ 'Gemini': '#ffe6e6', # Light pink
78
+ 'Cancer': '#e6f3ff', # Light blue
79
+ 'Leo': '#e8fde8', # Light green
80
+ 'Virgo': '#fff9e6', # Light yellow
81
+ 'Libra': '#ffe6e6', # Light pink
82
+ 'Scorpio': '#e6f3ff', # Light blue
83
+ 'Sagittarius': '#e8fde8', # Light green
84
+ 'Capricorn': '#fff9e6', # Light yellow
85
+ 'Aquarius': '#ffe6e6', # Light pink
86
+ 'Pisces': '#e6f3ff' # Light blue
87
+ }
88
+
89
+ # Create outer wheel segments (zodiac signs)
90
+ for i, (sign, color) in enumerate(zodiac_colors.items()):
91
+ start_angle = i * 30
92
+ end_angle = (i + 1) * 30
93
+
94
+ # Create arc for each sign
95
+ theta = np.linspace(start_angle, end_angle, 31)
96
+ r_outer = 1.2
97
+ r_inner = 1.0
98
+
99
+ x_outer = r_outer * np.cos(np.radians(theta))
100
+ y_outer = r_outer * np.sin(np.radians(theta))
101
+ x_inner = r_inner * np.cos(np.radians(theta))
102
+ y_inner = r_inner * np.sin(np.radians(theta))
103
+
104
+ # Combine points to form the segment
105
+ x = np.concatenate([x_outer, x_inner[::-1], [x_outer[0]]])
106
+ y = np.concatenate([y_outer, y_inner[::-1], [y_outer[0]]])
107
+
108
+ fig.add_trace(go.Scatter(
109
+ x=x, y=y,
110
+ fill='toself',
111
+ fillcolor=color,
112
+ line=dict(color='rgba(70, 70, 70, 0.5)', width=1),
113
+ hoverinfo='skip',
114
+ showlegend=False
115
+ ))
116
+
117
+ # Add degree markings
118
+ for degree in range(0, 360, 5):
119
+ r_start = 1.1
120
+ r_end = 1.15 if degree % 30 == 0 else 1.13
121
+ angle = np.radians(degree)
122
+
123
+ fig.add_trace(go.Scatter(
124
+ x=[r_start * np.cos(angle), r_end * np.cos(angle)],
125
+ y=[r_start * np.sin(angle), r_end * np.sin(angle)],
126
+ mode='lines',
127
+ line=dict(color='rgba(70, 70, 70, 0.5)', width=1),
128
+ hoverinfo='skip',
129
+ showlegend=False
130
+ ))
131
+
132
+ if degree % 30 == 0:
133
+ # Add zodiac symbols at sign boundaries
134
+ r_symbol = 1.25
135
+ x = r_symbol * np.cos(angle)
136
+ y = r_symbol * np.sin(angle)
137
+ zodiac_symbols = ['♈', '♉', '♊', '♋', '♌', '♍', '♎', '♏', '♐', '♑', '♒', '♓']
138
+ symbol = zodiac_symbols[degree // 30]
139
+
140
+ fig.add_annotation(
141
+ x=x, y=y,
142
+ text=symbol,
143
+ showarrow=False,
144
+ font=dict(size=20),
145
+ textangle=degree
146
+ )
147
+
148
+ # Add house lines
149
+ if 'houses' in chart_data and 'cusps' in chart_data['houses']:
150
+ for angle in chart_data['houses']['cusps']:
151
+ rad = np.radians(angle)
152
+ fig.add_trace(go.Scatter(
153
+ x=[0, np.cos(rad)],
154
+ y=[0, np.sin(rad)],
155
+ mode='lines',
156
+ line=dict(color='rgba(70, 70, 70, 0.7)', width=1, dash='dot'),
157
+ hoverinfo='skip',
158
+ showlegend=False
159
+ ))
160
+
161
+ # Add aspect grid in the center
162
+ if 'aspects' in chart_data:
163
+ for aspect in chart_data['aspects']:
164
+ planet1_pos = chart_data['planets'][aspect['planet1']]['degrees']
165
+ planet2_pos = chart_data['planets'][aspect['planet2']]['degrees']
166
+
167
+ # Define aspect line colors
168
+ aspect_colors = {
169
+ 'Conjunction': 'blue',
170
+ 'Sextile': 'green',
171
+ 'Square': 'red',
172
+ 'Trine': 'purple',
173
+ 'Opposition': 'orange'
174
+ }
175
+
176
+ rad1 = np.radians(planet1_pos)
177
+ rad2 = np.radians(planet2_pos)
178
+
179
+ # Draw aspect line
180
+ r_aspect = 0.4 # Size of aspect grid
181
+ fig.add_trace(go.Scatter(
182
+ x=[r_aspect * np.cos(rad1), r_aspect * np.cos(rad2)],
183
+ y=[r_aspect * np.sin(rad1), r_aspect * np.sin(rad2)],
184
+ mode='lines',
185
+ line=dict(
186
+ color=aspect_colors.get(aspect['aspect'], 'gray'),
187
+ width=1
188
+ ),
189
+ hoverinfo='text',
190
+ hovertext=f"{aspect['planet1']} {aspect['aspect']} {aspect['planet2']} ({aspect['orb']}°)",
191
+ showlegend=False
192
+ ))
193
+
194
+ # Add planets with proper symbols
195
+ planet_symbols = {
196
+ 'Sun': '☉',
197
+ 'Moon': '☽',
198
+ 'Mercury': '☿',
199
+ 'Venus': '♀',
200
+ 'Mars': '♂',
201
+ 'Jupiter': '♃',
202
+ 'Saturn': '♄',
203
+ 'Uranus': '⛢',
204
+ 'Neptune': '♆',
205
+ 'Pluto': '♇',
206
+ 'North Node': '☊',
207
+ 'Chiron': '⚷'
208
+ }
209
+
210
+ for planet, data in chart_data['planets'].items():
211
+ if 'error' not in data:
212
+ angle = np.radians(data['degrees'])
213
+ r = 0.8 # Planet placement radius
214
+
215
+ symbol = planet_symbols.get(planet, planet[:2])
216
+
217
+ # Add planet symbol
218
+ fig.add_annotation(
219
+ x=r * np.cos(angle),
220
+ y=r * np.sin(angle),
221
+ text=symbol,
222
+ showarrow=False,
223
+ font=dict(size=16),
224
+ hovertext=f"{planet} in {data['sign']} ({data['degrees']:.1f}°)",
225
+ hoverlabel=dict(bgcolor='white')
226
+ )
227
+
228
+ # Add degree marker
229
+ deg_text = f"{data['degrees']:.0f}°"
230
+ r_deg = 0.9
231
+ fig.add_annotation(
232
+ x=r_deg * np.cos(angle),
233
+ y=r_deg * np.sin(angle),
234
+ text=deg_text,
235
+ showarrow=False,
236
+ font=dict(size=8),
237
+ textangle=data['degrees']
238
+ )
239
+
240
+ # Update layout
241
+ fig.update_layout(
242
+ showlegend=False,
243
+ xaxis=dict(
244
+ range=[-1.3, 1.3],
245
+ showgrid=False,
246
+ zeroline=False,
247
+ showticklabels=False
248
+ ),
249
+ yaxis=dict(
250
+ range=[-1.3, 1.3],
251
+ showgrid=False,
252
+ zeroline=False,
253
+ showticklabels=False,
254
+ scaleanchor="x",
255
+ scaleratio=1
256
+ ),
257
+ plot_bgcolor='rgba(0,0,0,0)',
258
+ paper_bgcolor='rgba(0,0,0,0)',
259
+ margin=dict(l=20, r=20, t=20, b=20),
260
+ width=800,
261
+ height=800
262
+ )
263
+
264
+ return fig
265
+
266
  def init_session_state():
267
  """Initialize session state variables"""
268
  if 'birth_chart' not in st.session_state:
 
301
  except Exception as e:
302
  return {'error': f"Error finding location: {str(e)}"}
303
 
304
+ def display_chart_details(chart_data: Dict[str, Any]):
305
+ """Display detailed chart information"""
306
+ col1, col2, col3 = st.columns(3)
307
+
308
+ with col1:
309
+ st.markdown("### Planetary Positions")
310
+ for planet, data in chart_data['planets'].items():
311
+ if 'error' not in data:
312
+ st.markdown(f"""
313
+ <div class="element-card">
314
+ <strong>{planet}</strong><br>
315
+ {data['sign']} {data['degrees']:.1f}°<br>
316
+ House {data.get('house', 'Unknown')}<br>
317
+ {'🔄 Retrograde' if data.get('retrograde', False) else ''}
318
+ </div>
319
+ """, unsafe_allow_html=True)
320
+
321
+ with col2:
322
+ st.markdown("### Aspects")
323
+ if 'aspects' in chart_data:
324
+ for aspect in chart_data['aspects']:
325
+ st.markdown(f"""
326
+ <div class="element-card">
327
+ {aspect['planet1']} {aspect['aspect']} {aspect['planet2']}<br>
328
+ Orb: {aspect['orb']}° ({aspect['nature']})
329
+ </div>
330
+ """, unsafe_allow_html=True)
331
+
332
+ with col3:
333
+ st.markdown("### Elements & Modalities")
334
+ if 'patterns' in chart_data:
335
+ st.markdown("#### Element Balance")
336
+ element_data = pd.DataFrame(
337
+ chart_data['patterns']['elements'],
338
+ index=['Count']
339
+ ).T
340
+ st.bar_chart(element_data)
341
+
342
+ st.markdown("#### Modality Balance")
343
+ modality_data = pd.DataFrame(
344
+ chart_data['patterns']['modalities'],
345
+ index=['Count']
346
+ ).T
347
+ st.bar_chart(modality_data)
348
+
349
  def main():
350
  st.title("🌟 AI Astrology Assistant")
351
 
 
377
  placeholder="City, Country"
378
  )
379
 
380
+ calculate_button = st.form_submit_button(
381
+ "Calculate Birth Chart",
382
+ use_container_width=True
383
+ )
384
 
385
+ if calculate_button:
386
  if not birth_place:
387
  st.error("Please enter your birth place.")
388
  else:
 
415
 
416
  # Display chart and analysis if available
417
  if st.session_state.birth_chart and 'error' not in st.session_state.birth_chart:
418
+ tab1, tab2, tab3 = st.tabs(["Birth Chart", "Technical Details", "AI Analysis"])
419
 
420
  with tab1:
421
+ st.markdown("### Your Birth Chart")
422
+ chart_col1, chart_col2 = st.columns([2, 1])
423
+
424
+ with chart_col1:
425
+ st.plotly_chart(
426
+ create_chart_visualization(st.session_state.birth_chart),
427
+ use_container_width=True
428
+ )
429
+
430
+ with chart_col2:
431
+ st.markdown("### Quick Overview")
432
+ st.markdown("#### Rising Sign (Ascendant)")
433
+ if 'houses' in st.session_state.birth_chart:
434
+ rising_sign = st.session_state.birth_chart['houses']['ascendant']['sign']
435
+ st.markdown(f"Your Ascendant is in **{rising_sign}**")
436
+
437
+ st.markdown("#### Sun Sign")
438
+ sun_data = st.session_state.birth_chart['planets']['Sun']
439
+ st.markdown(f"Your Sun is in **{sun_data['sign']}**")
440
+
441
+ st.markdown("#### Moon Sign")
442
+ moon_data = st.session_state.birth_chart['planets']['Moon']
443
+ st.markdown(f"Your Moon is in **{moon_data['sign']}**")
444
 
445
  with tab2:
446
+ display_chart_details(st.session_state.birth_chart)
447
+
 
 
 
 
 
 
 
 
448
  with tab3:
449
  if st.session_state.initial_analysis:
450
+ st.markdown("### 🌟 Initial Chart Analysis")
451
  st.markdown(st.session_state.initial_analysis)
452
 
453
  # Chat interface
454
+ st.markdown("---")
455
  st.markdown("### 💬 Ask about your chart")
456
 
457
  # Suggested questions
458
  questions = [
459
+ "",
460
+ "What are the main themes in my birth chart?",
461
+ "What are my career strengths and potential paths?",
462
+ "How does my chart influence my relationships?",
463
+ "What are my biggest challenges and growth opportunities?",
464
+ "What are my spiritual or creative gifts?",
465
+ "How can I best work with my current planetary placements?",
466
+ "What areas of life are most emphasized in my chart?",
467
+ "How do my Sun, Moon, and Rising signs work together?",
468
+ "What are the most significant aspects in my chart?"
469
  ]
470
 
471
  selected_question = st.selectbox(
472
  "Choose a question or type your own below:",
473
+ questions,
474
+ label_visibility="collapsed"
475
  )
476
 
477
  user_question = st.text_input(
478
  "Your question:",
479
+ value=selected_question if selected_question != "" else "",
480
  key="user_input"
481
  )
482