cryogenic22 commited on
Commit
fab8679
·
verified ·
1 Parent(s): f794e31

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +118 -0
app.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ """
3
+ Main Streamlit application file for the AI Astrology app.
4
+ Supports both Western and Vedic astrology with AI interpretation.
5
+ """
6
+
7
+ import streamlit as st
8
+ from datetime import datetime
9
+ import pytz
10
+ from dotenv import load_dotenv
11
+ from astro_core import ChartCalculator, BirthInfo
12
+ from ai_interpreter import AstroAI
13
+
14
+ # Load environment variables
15
+ load_dotenv()
16
+
17
+ def init_session_state():
18
+ """Initialize session state variables"""
19
+ if 'birth_chart' not in st.session_state:
20
+ st.session_state.birth_chart = None
21
+ if 'astro_ai' not in st.session_state:
22
+ st.session_state.astro_ai = AstroAI()
23
+ if 'birth_time' not in st.session_state:
24
+ st.session_state.birth_time = None
25
+
26
+ def main():
27
+ st.title("AI Astrology Assistant")
28
+
29
+ # Initialize session state
30
+ init_session_state()
31
+
32
+ # Sidebar for user input
33
+ st.sidebar.header("Birth Information")
34
+
35
+ # System selection
36
+ system = st.sidebar.radio(
37
+ "Astrological System",
38
+ ['western', 'vedic'],
39
+ captions=['Tropical Zodiac', 'Sidereal Zodiac']
40
+ )
41
+
42
+ # Birth information inputs
43
+ date = st.sidebar.date_input("Birth Date", datetime.now())
44
+ time = st.sidebar.time_input("Birth Time", datetime.now().time())
45
+
46
+ # Location input
47
+ latitude = st.sidebar.number_input("Latitude", -90.0, 90.0, 0.0)
48
+ longitude = st.sidebar.number_input("Longitude", -180.0, 180.0, 0.0)
49
+ timezone = st.sidebar.selectbox("Timezone", pytz.all_timezones)
50
+
51
+ # Create calculator instance
52
+ calculator = ChartCalculator()
53
+
54
+ # Calculate button
55
+ if st.sidebar.button("Calculate Chart"):
56
+ with st.spinner(f"Calculating {system.title()} birth chart..."):
57
+ # Combine date and time
58
+ birth_datetime = datetime.combine(date, time)
59
+ st.session_state.birth_time = birth_datetime
60
+
61
+ # Create birth info
62
+ birth_info = BirthInfo(
63
+ datetime=birth_datetime,
64
+ latitude=latitude,
65
+ longitude=longitude,
66
+ timezone=timezone,
67
+ system=system
68
+ )
69
+
70
+ # Calculate chart
71
+ st.session_state.birth_chart = calculator.calculate_chart(birth_info)
72
+
73
+ # Initialize AI with new chart
74
+ st.session_state.astro_ai.initialize_context(
75
+ st.session_state.birth_chart,
76
+ birth_datetime
77
+ )
78
+
79
+ st.success("Chart calculated!")
80
+
81
+ # Display areas
82
+ col1, col2 = st.columns([2, 3])
83
+
84
+ with col1:
85
+ st.subheader("Birth Chart")
86
+ if st.session_state.birth_chart:
87
+ # Display system-specific chart data
88
+ if system == 'western':
89
+ st.write("### Planetary Positions")
90
+ for planet, data in st.session_state.birth_chart['planets'].items():
91
+ retrograde = " (R)" if data.get('retrograde') else ""
92
+ st.write(f"{planet}: {data['degrees']:.2f}° {data['sign']} in House {data['house']}{retrograde}")
93
+ else:
94
+ st.write("### Vedic Positions")
95
+ for planet, data in st.session_state.birth_chart['planets'].items():
96
+ st.write(f"{planet}: {data['degrees']:.2f}° in {data['rashi']}")
97
+ st.write(f"House: {data['house']}, Nakshatra: {data['nakshatra']}")
98
+
99
+ with col2:
100
+ st.subheader("AI Interpretation")
101
+ if st.session_state.birth_chart:
102
+ # Question input
103
+ user_question = st.text_input("Ask about your chart:")
104
+ if user_question:
105
+ with st.spinner("Generating interpretation..."):
106
+ interpretation = st.session_state.astro_ai.get_interpretation(user_question)
107
+ st.write("### Interpretation")
108
+ st.write(interpretation)
109
+
110
+ # Display previous interpretations
111
+ if st.session_state.astro_ai.context and st.session_state.astro_ai.context.discussion_history:
112
+ st.write("### Previous Interpretations")
113
+ for exchange in reversed(st.session_state.astro_ai.context.discussion_history[:-1]): # Skip the last one as it's already shown
114
+ with st.expander(f"Q: {exchange['question'][:50]}..."):
115
+ st.write(exchange['answer'])
116
+
117
+ if __name__ == "__main__":
118
+ main()