cryogenic22 commited on
Commit
54a7dbb
·
verified ·
1 Parent(s): 824f1f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +165 -5
app.py CHANGED
@@ -5,10 +5,9 @@ from geopy.geocoders import Nominatim
5
  from timezonefinder import TimezoneFinder
6
  from astro_core import ChartCalculator
7
  import plotly.graph_objects as go
 
8
  import pandas as pd
9
- import anthropic
10
  from typing import Dict, Any
11
- import json
12
 
13
  # Page configuration
14
  st.set_page_config(
@@ -53,6 +52,12 @@ st.markdown("""
53
  background-color: white;
54
  margin-right: 20%;
55
  }
 
 
 
 
 
 
56
  </style>
57
  """, unsafe_allow_html=True)
58
 
@@ -90,7 +95,6 @@ def get_location_details(location_name: str) -> Dict[str, Any]:
90
 
91
  def create_chart_visualization(chart_data: Dict[str, Any]):
92
  """Create an interactive circular chart visualization"""
93
- # Create circular chart layout
94
  fig = go.Figure()
95
 
96
  # Add zodiac ring
@@ -122,5 +126,161 @@ def create_chart_visualization(chart_data: Dict[str, Any]):
122
  # Update layout
123
  fig.update_layout(
124
  showlegend=False,
125
- xaxis=dict(range=[-1.2, 1.2], showgrid=False, zeroline=False, showticklabels=False),
126
- yaxis=dict(range=[-1.2, 1.2], showgrid=False, zeroline=False,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  from timezonefinder import TimezoneFinder
6
  from astro_core import ChartCalculator
7
  import plotly.graph_objects as go
8
+ import numpy as np
9
  import pandas as pd
 
10
  from typing import Dict, Any
 
11
 
12
  # Page configuration
13
  st.set_page_config(
 
52
  background-color: white;
53
  margin-right: 20%;
54
  }
55
+ .element-card {
56
+ background-color: white;
57
+ border-radius: 8px;
58
+ padding: 1rem;
59
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
60
+ }
61
  </style>
62
  """, unsafe_allow_html=True)
63
 
 
95
 
96
  def create_chart_visualization(chart_data: Dict[str, Any]):
97
  """Create an interactive circular chart visualization"""
 
98
  fig = go.Figure()
99
 
100
  # Add zodiac ring
 
126
  # Update layout
127
  fig.update_layout(
128
  showlegend=False,
129
+ xaxis=dict(
130
+ range=[-1.2, 1.2],
131
+ showgrid=False,
132
+ zeroline=False,
133
+ showticklabels=False
134
+ ),
135
+ yaxis=dict(
136
+ range=[-1.2, 1.2],
137
+ showgrid=False,
138
+ zeroline=False,
139
+ showticklabels=False
140
+ ),
141
+ plot_bgcolor='rgba(0,0,0,0)',
142
+ paper_bgcolor='rgba(0,0,0,0)',
143
+ height=600
144
+ )
145
+
146
+ return fig
147
+
148
+ def display_chart_analysis(chart_data: Dict[str, Any]):
149
+ """Display the chart analysis in a structured way"""
150
+ if 'error' in chart_data:
151
+ st.error(chart_data['error'])
152
+ return
153
+
154
+ # Create three columns for different aspects of the analysis
155
+ col1, col2, col3 = st.columns(3)
156
+
157
+ with col1:
158
+ st.markdown("### Planetary Positions")
159
+ for planet, data in chart_data['planets'].items():
160
+ if 'error' not in data:
161
+ st.markdown(f"""
162
+ <div class="element-card">
163
+ <strong>{planet}</strong><br>
164
+ {data['sign']} ({data['degrees']:.1f}°)<br>
165
+ House {data.get('house', 'Unknown')}<br>
166
+ {'🔄 Retrograde' if data.get('retrograde', False) else ''}
167
+ </div>
168
+ """, unsafe_allow_html=True)
169
+
170
+ with col2:
171
+ st.markdown("### Elements & Qualities")
172
+ element_data = pd.DataFrame(chart_data['patterns']['elements'], index=['Count']).T
173
+ st.bar_chart(element_data)
174
+
175
+ quality_data = pd.DataFrame(chart_data['patterns']['modalities'], index=['Count']).T
176
+ st.bar_chart(quality_data)
177
+
178
+ with col3:
179
+ st.markdown("### Major Aspects")
180
+ for aspect in chart_data['aspects']:
181
+ st.markdown(f"""
182
+ <div class="element-card">
183
+ {aspect['planet1']} {aspect['aspect']} {aspect['planet2']}<br>
184
+ Orb: {aspect['orb']}° ({aspect['nature']})
185
+ </div>
186
+ """, unsafe_allow_html=True)
187
+
188
+ def main():
189
+ st.title("🌟 AI Astrology Assistant")
190
+
191
+ # Initialize session state
192
+ init_session_state()
193
+
194
+ # Birth Information Form
195
+ with st.form("birth_info"):
196
+ st.subheader("Enter Birth Details")
197
+
198
+ col1, col2 = st.columns(2)
199
+
200
+ with col1:
201
+ birth_date = st.date_input(
202
+ "Birth Date",
203
+ min_value=datetime(1900, 1, 1),
204
+ max_value=datetime.now()
205
+ )
206
+ birth_time = st.time_input("Birth Time")
207
+
208
+ with col2:
209
+ birth_place = st.text_input(
210
+ "Birth Place",
211
+ placeholder="City, Country"
212
+ )
213
+
214
+ submit = st.form_submit_button("Calculate Birth Chart")
215
+
216
+ if submit:
217
+ if not birth_place:
218
+ st.error("Please enter your birth place.")
219
+ else:
220
+ with st.spinner("Looking up location and calculating chart..."):
221
+ # Get location details
222
+ location = get_location_details(birth_place)
223
+
224
+ if location.get('error'):
225
+ st.error(location['error'])
226
+ else:
227
+ # Calculate chart
228
+ calculator = ChartCalculator()
229
+ birth_datetime = datetime.combine(birth_date, birth_time)
230
+
231
+ st.session_state.birth_chart = calculator.calculate_birth_chart(
232
+ birth_datetime,
233
+ location['latitude'],
234
+ location['longitude']
235
+ )
236
+
237
+ if 'error' in st.session_state.birth_chart:
238
+ st.error(st.session_state.birth_chart['error'])
239
+ else:
240
+ st.success("Birth chart calculated successfully!")
241
+
242
+ # Display chart and analysis if available
243
+ if st.session_state.birth_chart and 'error' not in st.session_state.birth_chart:
244
+ # Tabs for different views
245
+ tab1, tab2 = st.tabs(["Chart Visualization", "Detailed Analysis"])
246
+
247
+ with tab1:
248
+ st.plotly_chart(
249
+ create_chart_visualization(st.session_state.birth_chart),
250
+ use_container_width=True
251
+ )
252
+
253
+ with tab2:
254
+ display_chart_analysis(st.session_state.birth_chart)
255
+
256
+ # Chat interface
257
+ st.markdown("### 💬 Ask about your chart")
258
+ user_question = st.text_input("Enter your question about your birth chart")
259
+
260
+ if user_question:
261
+ # Add user message to chat history
262
+ st.session_state.chat_history.append({
263
+ "role": "user",
264
+ "content": user_question
265
+ })
266
+
267
+ # Generate response (implement AI response logic here)
268
+ response = "This is a placeholder response. Implement actual AI response logic."
269
+
270
+ st.session_state.chat_history.append({
271
+ "role": "assistant",
272
+ "content": response
273
+ })
274
+
275
+ # Display chat history
276
+ for message in st.session_state.chat_history:
277
+ st.markdown(
278
+ f"""<div class="chat-message {'user-message' if message['role'] == 'user' else 'assistant-message'}">
279
+ <strong>{'You' if message['role'] == 'user' else '🔮 Assistant'}:</strong><br>
280
+ {message['content']}
281
+ </div>""",
282
+ unsafe_allow_html=True
283
+ )
284
+
285
+ if __name__ == "__main__":
286
+ main()