File size: 6,015 Bytes
9d63cb3
fab8679
b341f9d
9d63cb3
 
3615e00
07ed5b8
b341f9d
54a7dbb
b341f9d
 
9d63cb3
b341f9d
 
 
 
 
 
 
9d63cb3
42d9e4d
b341f9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07ed5b8
 
 
 
b341f9d
 
 
 
07ed5b8
b341f9d
 
 
 
07ed5b8
54a7dbb
cf52217
 
 
 
 
 
 
b341f9d
 
 
e6107c9
42d9e4d
e6107c9
 
 
 
 
 
 
cf52217
42d9e4d
 
 
 
 
 
 
 
b341f9d
42d9e4d
b341f9d
 
 
 
 
 
07ed5b8
 
 
 
 
 
 
 
b341f9d
 
42d9e4d
9d63cb3
 
 
 
 
 
b341f9d
 
 
 
 
 
 
9d63cb3
 
b341f9d
9d63cb3
cf52217
42d9e4d
cf52217
42d9e4d
 
cf52217
54a7dbb
 
 
42d9e4d
07ed5b8
42d9e4d
07ed5b8
 
54a7dbb
 
 
 
 
 
 
 
 
 
 
 
42d9e4d
 
 
cf52217
54a7dbb
 
 
42d9e4d
54a7dbb
 
 
 
 
 
 
 
 
 
 
42d9e4d
07ed5b8
42d9e4d
 
 
54a7dbb
42d9e4d
54a7dbb
cf52217
07ed5b8
42d9e4d
54a7dbb
 
e6107c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import streamlit as st
from datetime import datetime
import pytz
from geopy.geocoders import Nominatim
from timezonefinder import TimezoneFinder
from astro_core import ChartCalculator
from ai_interpreter import AstroAI
import plotly.graph_objects as go
import numpy as np
import pandas as pd
from typing import Dict, Any

# Page configuration
st.set_page_config(
    page_title="AI Astrology Assistant",
    page_icon="🌟",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Custom CSS
st.markdown("""
    <style>
    .stApp {
        background: linear-gradient(135deg, #f5f7ff 0%, #f8f0ff 100%);
    }
    .main {
        background-color: transparent;
    }
    .stTextInput > div > div > input {
        background-color: rgba(255, 255, 255, 0.8);
    }
    .stButton > button {
        background-color: #6B46C1;
        color: white;
        border-radius: 8px;
        padding: 0.5rem 1rem;
        border: none;
    }
    .chat-message {
        padding: 1.5rem;
        border-radius: 10px;
        margin-bottom: 1rem;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }
    .user-message {
        background-color: rgba(107, 70, 193, 0.1);
        margin-left: 20%;
        border-left: 4px solid #6B46C1;
    }
    .assistant-message {
        background-color: white;
        margin-right: 20%;
        border-left: 4px solid #9F7AEA;
    }
    .element-card {
        background-color: white;
        padding: 1rem;
        border-radius: 8px;
        margin-bottom: 0.5rem;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }
    </style>
""", unsafe_allow_html=True)

def get_safe_planet_data(chart_data: Dict[str, Any], planet: str) -> Dict[str, Any]:
    """Safely get planet data with error handling."""
    try:
        planet_data = chart_data.get('planets', {}).get(planet, {})
        if 'error' in planet_data or not planet_data:
            return {'error': f"Could not calculate {planet} position"}
        return planet_data
    except Exception as e:
        return {'error': str(e)}

def create_chart_visualization(chart_data: Dict[str, Any]) -> go.Figure:
    """Create a professional astrological chart visualization."""
    fig = go.Figure()
    # Define colors for zodiac signs and create the chart
    # ...

    return fig

def init_session_state():
    """Initialize session state variables."""
    if 'birth_chart' not in st.session_state:
        st.session_state.birth_chart = None
    if 'chat_history' not in st.session_state:
        st.session_state.chat_history = []
    if 'location_details' not in st.session_state:
        st.session_state.location_details = None
    if 'ai_interpreter' not in st.session_state:
        try:
            st.session_state.ai_interpreter = AstroAI()
        except ValueError as e:
            st.error(str(e))
            st.session_state.ai_interpreter = None
    if 'initial_analysis' not in st.session_state:
        st.session_state.initial_analysis = None

def get_location_details(location_name: str) -> Dict[str, Any]:
    """Get coordinates and timezone for a location."""
    try:
        geolocator = Nominatim(user_agent="ai_astrology_app")
        tf = TimezoneFinder()
        location = geolocator.geocode(location_name)
        if location:
            latitude, longitude = location.latitude, location.longitude
            timezone_str = tf.timezone_at(lat=latitude, lng=longitude) or 'UTC'
            return {
                'latitude': latitude,
                'longitude': longitude,
                'timezone': timezone_str,
                'error': None
            }
        return {'error': 'Location not found'}
    except Exception as e:
        return {'error': f"Error finding location: {str(e)}"}

def display_chart_details(chart_data: Dict[str, Any]):
    """Display detailed chart information."""
    col1, col2, col3 = st.columns(3)
    # Display planetary positions, aspects, and elements/modalities
    # ...

def main():
    st.title("🌟 AI Astrology Assistant")
    init_session_state()

    if st.session_state.ai_interpreter is None:
        st.warning("⚠️ Astro AI not initialized. Please configure your API key.")
        return

    # Birth Information Form
    with st.form("birth_info"):
        st.subheader("Enter Birth Details")
        col1, col2 = st.columns(2)
        with col1:
            birth_date = st.date_input(
                "Birth Date",
                min_value=datetime(1900, 1, 1),
                max_value=datetime.now()
            )
            birth_time = st.time_input("Birth Time")
        with col2:
            birth_place = st.text_input("Birth Place", placeholder="City, Country")
        calculate_button = st.form_submit_button("Calculate Birth Chart")

        if calculate_button:
            if not birth_place:
                st.error("Please enter your birth place.")
            else:
                with st.spinner("Calculating..."):
                    location = get_location_details(birth_place)
                    if location.get('error'):
                        st.error(location['error'])
                    else:
                        calculator = ChartCalculator()
                        birth_datetime = datetime.combine(birth_date, birth_time)
                        st.session_state.birth_chart = calculator.calculate_birth_chart(
                            birth_datetime,
                            location['latitude'],
                            location['longitude']
                        )
                        st.success("Birth chart calculated!")

    # Display results
    if st.session_state.birth_chart:
        tab1, tab2, tab3 = st.tabs(["Birth Chart", "Details", "AI Analysis"])
        with tab1:
            st.plotly_chart(create_chart_visualization(st.session_state.birth_chart))
        with tab2:
            display_chart_details(st.session_state.birth_chart)
        with tab3:
            st.write(st.session_state.initial_analysis)

if __name__ == "__main__":
    main()