cryogenic22 commited on
Commit
b341f9d
Β·
verified Β·
1 Parent(s): 3615e00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -66
app.py CHANGED
@@ -1,82 +1,126 @@
1
  import streamlit as st
2
  from datetime import datetime
 
3
  from geopy.geocoders import Nominatim
4
- from geopy.exc import GeocoderTimedOut, GeocoderServiceError
5
  from timezonefinder import TimezoneFinder
6
- from dotenv import load_dotenv
7
  from astro_core import ChartCalculator
 
 
 
 
 
8
 
9
- load_dotenv()
 
 
 
 
 
 
10
 
11
- def get_location_details(location_name: str) -> dict:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  try:
13
  geolocator = Nominatim(user_agent="ai_astrology_app")
14
  tf = TimezoneFinder()
 
15
  location = geolocator.geocode(location_name)
16
  if location:
17
  latitude, longitude = location.latitude, location.longitude
18
- timezone_str = tf.timezone_at(lng=longitude, lat=latitude)
19
- if not timezone_str:
20
- timezone_str = 'UTC'
21
- return {'latitude': latitude, 'longitude': longitude, 'timezone': timezone_str, 'error': None}
 
 
 
 
22
  return {'error': 'Location not found'}
23
- except (GeocoderTimedOut, GeocoderServiceError) as e:
24
- return {'error': f'Geocoding error: {str(e)}'}
25
  except Exception as e:
26
- return {'error': f'Unexpected error: {str(e)}'}
27
-
28
- def calculate_chart(user_data: dict):
29
- calculator = ChartCalculator()
30
- birth_datetime = datetime.combine(user_data['birth_date'], user_data['birth_time'])
31
- return calculator.calculate_birth_chart(
32
- birth_datetime,
33
- user_data['latitude'],
34
- user_data['longitude'],
35
- user_data['timezone']
36
- )
37
-
38
- def main():
39
- st.title("AI Astrology Assistant")
40
-
41
- with st.form("user_info_form"):
42
- name = st.text_input("Full Name")
43
- birth_date = st.date_input("Birth Date", min_value=datetime(1900, 1, 1))
44
- birth_time = st.time_input("Birth Time")
45
- birth_place = st.text_input("Birth Place (City, Country)")
46
- submit_button = st.form_submit_button("Generate Birth Chart")
47
-
48
- if submit_button:
49
- if not birth_place:
50
- st.error("Please enter your birth place.")
51
- else:
52
- with st.spinner("Fetching location details..."):
53
- location_details = get_location_details(birth_place)
54
-
55
- if location_details.get('error'):
56
- st.error(location_details['error'])
57
- else:
58
- user_data = {
59
- 'name': name,
60
- 'birth_date': birth_date,
61
- 'birth_time': birth_time,
62
- 'latitude': location_details['latitude'],
63
- 'longitude': location_details['longitude'],
64
- 'timezone': location_details['timezone']
65
- }
66
-
67
- with st.spinner("Calculating birth chart..."):
68
- birth_chart = calculate_chart(user_data)
69
-
70
- if 'error' in birth_chart:
71
- st.error(f"Error: {birth_chart['error']}")
72
- else:
73
- st.success("Birth chart calculated successfully!")
74
- st.write("**Planetary Positions:**")
75
- for planet, data in birth_chart['planets'].items():
76
- if 'error' in data:
77
- st.write(f"{planet}: {data['error']}")
78
- else:
79
- st.write(f"{planet}: {data['degrees']:.2f}Β° {data['sign']}")
80
 
81
- if __name__ == "__main__":
82
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from datetime import datetime
3
+ import pytz
4
  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(
15
+ page_title="AI Astrology Assistant",
16
+ page_icon="🌟",
17
+ layout="wide",
18
+ initial_sidebar_state="expanded"
19
+ )
20
 
21
+ # Custom CSS for a more modern look
22
+ st.markdown("""
23
+ <style>
24
+ .stApp {
25
+ background: linear-gradient(135deg, #f5f7ff 0%, #f8f0ff 100%);
26
+ }
27
+ .main {
28
+ background-color: transparent;
29
+ }
30
+ .stTextInput > div > div > input {
31
+ background-color: rgba(255, 255, 255, 0.8);
32
+ }
33
+ .stButton > button {
34
+ background-color: #6B46C1;
35
+ color: white;
36
+ border-radius: 8px;
37
+ padding: 0.5rem 1rem;
38
+ border: none;
39
+ }
40
+ .stButton > button:hover {
41
+ background-color: #553C9A;
42
+ }
43
+ .chat-message {
44
+ padding: 1rem;
45
+ border-radius: 8px;
46
+ margin-bottom: 0.5rem;
47
+ }
48
+ .user-message {
49
+ background-color: rgba(107, 70, 193, 0.1);
50
+ margin-left: 20%;
51
+ }
52
+ .assistant-message {
53
+ background-color: white;
54
+ margin-right: 20%;
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:
62
+ st.session_state.birth_chart = None
63
+ if 'chat_history' not in st.session_state:
64
+ st.session_state.chat_history = []
65
+ if 'location_details' not in st.session_state:
66
+ st.session_state.location_details = None
67
+ if 'chart_analysis' not in st.session_state:
68
+ st.session_state.chart_analysis = None
69
+
70
+ def get_location_details(location_name: str) -> Dict[str, Any]:
71
+ """Get coordinates and timezone for a location"""
72
  try:
73
  geolocator = Nominatim(user_agent="ai_astrology_app")
74
  tf = TimezoneFinder()
75
+
76
  location = geolocator.geocode(location_name)
77
  if location:
78
  latitude, longitude = location.latitude, location.longitude
79
+ timezone_str = tf.timezone_at(lat=latitude, lng=longitude) or 'UTC'
80
+
81
+ return {
82
+ 'latitude': latitude,
83
+ 'longitude': longitude,
84
+ 'timezone': timezone_str,
85
+ 'error': None
86
+ }
87
  return {'error': 'Location not found'}
 
 
88
  except Exception as e:
89
+ return {'error': f"Error finding location: {str(e)}"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
97
+ zodiac_positions = list(range(0, 360, 30))
98
+ zodiac_signs = ['β™ˆ', '♉', 'β™Š', 'β™‹', 'β™Œ', '♍', 'β™Ž', '♏', '♐', 'β™‘', 'β™’', 'β™“']
99
+
100
+ for pos, sign in zip(zodiac_positions, zodiac_signs):
101
+ fig.add_annotation(
102
+ x=1.1 * np.cos(np.radians(pos)),
103
+ y=1.1 * np.sin(np.radians(pos)),
104
+ text=sign,
105
+ showarrow=False,
106
+ font=dict(size=20)
107
+ )
108
+
109
+ # Add planets
110
+ for planet, data in chart_data['planets'].items():
111
+ if 'error' not in data:
112
+ angle = np.radians(data['longitude'])
113
+ r = 0.8 # Radius for planets
114
+ fig.add_annotation(
115
+ x=r * np.cos(angle),
116
+ y=r * np.sin(angle),
117
+ text=planet,
118
+ showarrow=True,
119
+ arrowhead=2
120
+ )
121
+
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,