Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# zodiac_app.py (Streamlit version)
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import datetime
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import io
|
| 7 |
+
|
| 8 |
+
# Data: zodiac signs with date ranges and personality traits
|
| 9 |
+
zodiac_traits = {
|
| 10 |
+
'Aries': {'dates': ((3,21), (4,19)), 'traits': ['Courageous', 'Determined', 'Confident', 'Enthusiastic']},
|
| 11 |
+
'Taurus': {'dates': ((4,20), (5,20)), 'traits': ['Reliable', 'Patient', 'Practical', 'Devoted']},
|
| 12 |
+
'Gemini': {'dates': ((5,21), (6,20)), 'traits': ['Gentle', 'Affectionate', 'Curious', 'Adaptable']},
|
| 13 |
+
'Cancer': {'dates': ((6,21), (7,22)), 'traits': ['Tenacious', 'Highly Imaginative', 'Loyal', 'Emotional']},
|
| 14 |
+
'Leo': {'dates': ((7,23), (8,22)), 'traits': ['Creative', 'Passionate', 'Generous', 'Warmhearted']},
|
| 15 |
+
'Virgo': {'dates': ((8,23), (9,22)), 'traits': ['Loyal', 'Analytical', 'Kind', 'Hardworking']},
|
| 16 |
+
'Libra': {'dates': ((9,23), (10,22)), 'traits': ['Cooperative', 'Diplomatic', 'Gracious', 'Fair-minded']},
|
| 17 |
+
'Scorpio': {'dates': ((10,23), (11,21)), 'traits': ['Resourceful', 'Brave', 'Passionate', 'Stubborn']},
|
| 18 |
+
'Sagittarius': {'dates': ((11,22), (12,21)), 'traits': ['Generous', 'Idealistic', 'Great Sense of Humor']},
|
| 19 |
+
'Capricorn': {'dates': ((12,22), (1,19)), 'traits': ['Responsible', 'Disciplined', 'Self-control', 'Good Managers']},
|
| 20 |
+
'Aquarius': {'dates': ((1,20), (2,18)), 'traits': ['Progressive', 'Original', 'Independent', 'Humanitarian']},
|
| 21 |
+
'Pisces': {'dates': ((2,19), (3,20)), 'traits': ['Compassionate', 'Artistic', 'Intuitive', 'Gentle']},
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
# Compatibility scores between signs (1-10)
|
| 25 |
+
compatibility = pd.DataFrame(
|
| 26 |
+
data=[
|
| 27 |
+
[5,6,7,4,8,5,6,7,8,5,6,7], # Aries with Aries, Taurus, ... Pisces
|
| 28 |
+
[6,5,6,7,5,8,7,6,5,8,7,6],
|
| 29 |
+
[7,6,5,8,6,7,8,5,6,7,8,5],
|
| 30 |
+
[4,7,8,5,7,6,5,8,7,6,5,8],
|
| 31 |
+
[8,5,6,7,5,7,6,7,5,8,6,7],
|
| 32 |
+
[5,8,7,6,7,5,8,6,7,5,8,6],
|
| 33 |
+
[6,7,8,5,6,8,5,7,6,8,7,5],
|
| 34 |
+
[7,6,5,8,7,6,7,5,8,6,7,6],
|
| 35 |
+
[8,5,6,7,5,7,6,8,5,7,6,8],
|
| 36 |
+
[5,8,7,6,8,5,8,6,7,5,8,6],
|
| 37 |
+
[6,7,8,5,6,8,7,7,6,8,5,7],
|
| 38 |
+
[7,6,5,8,7,6,5,6,8,6,7,5]
|
| 39 |
+
],
|
| 40 |
+
index=list(zodiac_traits.keys()),
|
| 41 |
+
columns=list(zodiac_traits.keys())
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Helper to determine zodiac sign from birthdate
|
| 45 |
+
def get_zodiac_sign(month: int, day: int) -> str:
|
| 46 |
+
for sign, info in zodiac_traits.items():
|
| 47 |
+
start, end = info['dates']
|
| 48 |
+
start_month, start_day = start
|
| 49 |
+
end_month, end_day = end
|
| 50 |
+
# handle year wrap for Capricorn
|
| 51 |
+
if start_month == 12:
|
| 52 |
+
if (month == start_month and day >= start_day) or (month == end_month and day <= end_day):
|
| 53 |
+
return sign
|
| 54 |
+
else:
|
| 55 |
+
if (month == start_month and day >= start_day) or (month == end_month and day <= end_day) or (start_month < month < end_month):
|
| 56 |
+
return sign
|
| 57 |
+
return None
|
| 58 |
+
|
| 59 |
+
# Streamlit UI
|
| 60 |
+
st.title('Zodiac App')
|
| 61 |
+
|
| 62 |
+
# Horoscope Section
|
| 63 |
+
st.header('Get Your Horoscope and Personality Traits')
|
| 64 |
+
|
| 65 |
+
birthdate = st.date_input("Enter your birthdate:")
|
| 66 |
+
|
| 67 |
+
if birthdate:
|
| 68 |
+
dt = datetime.datetime.strptime(str(birthdate), '%Y-%m-%d')
|
| 69 |
+
sign = get_zodiac_sign(dt.month, dt.day)
|
| 70 |
+
traits = zodiac_traits[sign]['traits']
|
| 71 |
+
st.subheader(f"Your zodiac sign is: {sign}")
|
| 72 |
+
st.write(f"Personality Traits: {', '.join(traits)}")
|
| 73 |
+
|
| 74 |
+
# Compatibility Section
|
| 75 |
+
st.header('Check Compatibility Between Two Zodiac Signs')
|
| 76 |
+
|
| 77 |
+
sign1 = st.selectbox('Select your sign:', list(zodiac_traits.keys()))
|
| 78 |
+
sign2 = st.selectbox('Select partner sign:', list(zodiac_traits.keys()))
|
| 79 |
+
|
| 80 |
+
if sign1 and sign2:
|
| 81 |
+
score = compatibility.at[sign1, sign2]
|
| 82 |
+
st.subheader(f"Compatibility Score between {sign1} and {sign2}: {score}")
|
| 83 |
+
|
| 84 |
+
# Plotting Compatibility Chart
|
| 85 |
+
fig, ax = plt.subplots()
|
| 86 |
+
ax.bar([sign1 + " & " + sign2], [score])
|
| 87 |
+
ax.set_ylim(0, 10)
|
| 88 |
+
ax.set_ylabel('Score (1-10)')
|
| 89 |
+
ax.set_title(f'{sign1} & {sign2} Compatibility')
|
| 90 |
+
|
| 91 |
+
buf = io.BytesIO()
|
| 92 |
+
plt.savefig(buf, format='png')
|
| 93 |
+
buf.seek(0)
|
| 94 |
+
st.image(buf)
|