Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from datetime import datetime | |
| import pytz | |
| from geopy.geocoders import Nominatim | |
| from timezonefinder import TimezoneFinder | |
| from astro_core import ChartCalculator | |
| import plotly.graph_objects as go | |
| import pandas as pd | |
| import anthropic | |
| from typing import Dict, Any | |
| import json | |
| # Page configuration | |
| st.set_page_config( | |
| page_title="AI Astrology Assistant", | |
| page_icon="π", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Custom CSS for a more modern look | |
| 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; | |
| } | |
| .stButton > button:hover { | |
| background-color: #553C9A; | |
| } | |
| .chat-message { | |
| padding: 1rem; | |
| border-radius: 8px; | |
| margin-bottom: 0.5rem; | |
| } | |
| .user-message { | |
| background-color: rgba(107, 70, 193, 0.1); | |
| margin-left: 20%; | |
| } | |
| .assistant-message { | |
| background-color: white; | |
| margin-right: 20%; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| 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 'chart_analysis' not in st.session_state: | |
| st.session_state.chart_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 create_chart_visualization(chart_data: Dict[str, Any]): | |
| """Create an interactive circular chart visualization""" | |
| # Create circular chart layout | |
| fig = go.Figure() | |
| # Add zodiac ring | |
| zodiac_positions = list(range(0, 360, 30)) | |
| zodiac_signs = ['β', 'β', 'β', 'β', 'β', 'β', 'β', 'β', 'β', 'β', 'β', 'β'] | |
| for pos, sign in zip(zodiac_positions, zodiac_signs): | |
| fig.add_annotation( | |
| x=1.1 * np.cos(np.radians(pos)), | |
| y=1.1 * np.sin(np.radians(pos)), | |
| text=sign, | |
| showarrow=False, | |
| font=dict(size=20) | |
| ) | |
| # Add planets | |
| for planet, data in chart_data['planets'].items(): | |
| if 'error' not in data: | |
| angle = np.radians(data['longitude']) | |
| r = 0.8 # Radius for planets | |
| fig.add_annotation( | |
| x=r * np.cos(angle), | |
| y=r * np.sin(angle), | |
| text=planet, | |
| showarrow=True, | |
| arrowhead=2 | |
| ) | |
| # Update layout | |
| fig.update_layout( | |
| showlegend=False, | |
| xaxis=dict(range=[-1.2, 1.2], showgrid=False, zeroline=False, showticklabels=False), | |
| yaxis=dict(range=[-1.2, 1.2], showgrid=False, zeroline=False, |