azeus commited on
Commit
5e1827b
·
1 Parent(s): 27d6f58

Add application file

Browse files
Files changed (2) hide show
  1. app.py +155 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from datetime import datetime
4
+ import swisseph as swe
5
+ import pytz
6
+ from transformers import pipeline
7
+ import numpy as np
8
+
9
+ # Set page config
10
+ st.set_page_config(
11
+ page_title="Hindu Astrology Daily Prediction",
12
+ page_icon="🔮",
13
+ layout="wide"
14
+ )
15
+
16
+ # Initialize the text generation pipeline
17
+ generator = pipeline('text-generation', model='gpt2')
18
+
19
+
20
+ def calculate_planetary_positions(birth_date, birth_time):
21
+ """Calculate planetary positions at the time of birth."""
22
+ # Convert birth datetime to Julian day
23
+ date_time = datetime.combine(birth_date, birth_time)
24
+ julian_day = swe.julday(
25
+ date_time.year,
26
+ date_time.month,
27
+ date_time.day,
28
+ date_time.hour + date_time.minute / 60.0
29
+ )
30
+
31
+ # List of planets to calculate (Sun to Pluto)
32
+ planets = range(0, 10)
33
+ positions = {}
34
+
35
+ for planet in planets:
36
+ position = swe.calc_ut(julian_day, planet)[0]
37
+ positions[planet] = position[0] # longitude in degrees
38
+
39
+ return positions
40
+
41
+
42
+ def get_zodiac_sign(longitude):
43
+ """Convert longitude to zodiac sign."""
44
+ signs = [
45
+ "Aries", "Taurus", "Gemini", "Cancer",
46
+ "Leo", "Virgo", "Libra", "Scorpio",
47
+ "Sagittarius", "Capricorn", "Aquarius", "Pisces"
48
+ ]
49
+ sign_index = int(longitude / 30)
50
+ return signs[sign_index]
51
+
52
+
53
+ def generate_prediction(planetary_positions):
54
+ """Generate daily prediction based on planetary positions."""
55
+ # Create a prompt based on planetary positions
56
+ prompt = "Based on your planetary positions:\n"
57
+ planet_names = [
58
+ "Sun", "Moon", "Mercury", "Venus", "Mars",
59
+ "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"
60
+ ]
61
+
62
+ aspects = []
63
+ for i, planet1 in enumerate(planetary_positions):
64
+ sign1 = get_zodiac_sign(planetary_positions[planet1])
65
+ prompt += f"{planet_names[i]} in {sign1}\n"
66
+
67
+ # Calculate aspects between planets
68
+ for j, planet2 in enumerate(planetary_positions):
69
+ if i < j:
70
+ angle = abs(planetary_positions[planet1] - planetary_positions[planet2])
71
+ if abs(angle - 120) < 10: # Trine
72
+ aspects.append(f"Trine between {planet_names[i]} and {planet_names[j]}")
73
+ elif abs(angle - 90) < 10: # Square
74
+ aspects.append(f"Square between {planet_names[i]} and {planet_names[j]}")
75
+
76
+ prompt += "\nSignificant aspects:\n" + "\n".join(aspects)
77
+ prompt += "\nDaily prediction: "
78
+
79
+ # Generate prediction using the model
80
+ prediction = generator(
81
+ prompt,
82
+ max_length=200,
83
+ num_return_sequences=1,
84
+ temperature=0.7
85
+ )[0]['generated_text']
86
+
87
+ # Clean up the prediction
88
+ prediction = prediction.split("Daily prediction: ")[-1].strip()
89
+ return prediction
90
+
91
+
92
+ # Streamlit UI
93
+ st.title("🔮 Hindu Astrology Daily Prediction")
94
+ st.write("Enter your birth details to receive your personalized daily prediction.")
95
+
96
+ # Input forms
97
+ col1, col2 = st.columns(2)
98
+
99
+ with col1:
100
+ birth_date = st.date_input(
101
+ "Date of Birth",
102
+ min_value=datetime(1900, 1, 1),
103
+ max_value=datetime.now()
104
+ )
105
+
106
+ with col2:
107
+ birth_time = st.time_input("Time of Birth")
108
+
109
+ # Time zone selection
110
+ timezone = st.selectbox(
111
+ "Select Your Time Zone",
112
+ options=pytz.all_timezones,
113
+ index=pytz.all_timezones.index('UTC')
114
+ )
115
+
116
+ if st.button("Get Prediction"):
117
+ with st.spinner("Calculating planetary positions and generating prediction..."):
118
+ try:
119
+ # Calculate planetary positions
120
+ positions = calculate_planetary_positions(birth_date, birth_time)
121
+
122
+ # Display planetary positions
123
+ st.subheader("Planetary Positions at Birth")
124
+ planet_names = [
125
+ "Sun", "Moon", "Mercury", "Venus", "Mars",
126
+ "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"
127
+ ]
128
+
129
+ planet_data = []
130
+ for i, planet in enumerate(positions):
131
+ sign = get_zodiac_sign(positions[planet])
132
+ planet_data.append({
133
+ "Planet": planet_names[i],
134
+ "Sign": sign,
135
+ "Degrees": f"{positions[planet]:.2f}°"
136
+ })
137
+
138
+ df = pd.DataFrame(planet_data)
139
+ st.table(df)
140
+
141
+ # Generate and display prediction
142
+ st.subheader("Your Daily Prediction")
143
+ prediction = generate_prediction(positions)
144
+ st.write(prediction)
145
+
146
+ # Add disclaimer
147
+ st.markdown("---")
148
+ st.caption(
149
+ "Disclaimer: This prediction is generated using AI and should be taken "
150
+ "as entertainment only. For accurate astrological readings, please "
151
+ "consult a professional astrologer."
152
+ )
153
+
154
+ except Exception as e:
155
+ st.error(f"An error occurred: {str(e)}")
requirements.txt ADDED
File without changes