Spaces:
Sleeping
Sleeping
| # zodiac_app.py (Streamlit version) | |
| import streamlit as st | |
| import pandas as pd | |
| import datetime | |
| import matplotlib.pyplot as plt | |
| import io | |
| # Data: zodiac signs with date ranges and personality traits | |
| zodiac_traits = { | |
| 'Aries': {'dates': ((3,21), (4,19)), 'traits': ['Courageous', 'Determined', 'Confident', 'Enthusiastic']}, | |
| 'Taurus': {'dates': ((4,20), (5,20)), 'traits': ['Reliable', 'Patient', 'Practical', 'Devoted']}, | |
| 'Gemini': {'dates': ((5,21), (6,20)), 'traits': ['Gentle', 'Affectionate', 'Curious', 'Adaptable']}, | |
| 'Cancer': {'dates': ((6,21), (7,22)), 'traits': ['Tenacious', 'Highly Imaginative', 'Loyal', 'Emotional']}, | |
| 'Leo': {'dates': ((7,23), (8,22)), 'traits': ['Creative', 'Passionate', 'Generous', 'Warmhearted']}, | |
| 'Virgo': {'dates': ((8,23), (9,22)), 'traits': ['Loyal', 'Analytical', 'Kind', 'Hardworking']}, | |
| 'Libra': {'dates': ((9,23), (10,22)), 'traits': ['Cooperative', 'Diplomatic', 'Gracious', 'Fair-minded']}, | |
| 'Scorpio': {'dates': ((10,23), (11,21)), 'traits': ['Resourceful', 'Brave', 'Passionate', 'Stubborn']}, | |
| 'Sagittarius': {'dates': ((11,22), (12,21)), 'traits': ['Generous', 'Idealistic', 'Great Sense of Humor']}, | |
| 'Capricorn': {'dates': ((12,22), (1,19)), 'traits': ['Responsible', 'Disciplined', 'Self-control', 'Good Managers']}, | |
| 'Aquarius': {'dates': ((1,20), (2,18)), 'traits': ['Progressive', 'Original', 'Independent', 'Humanitarian']}, | |
| 'Pisces': {'dates': ((2,19), (3,20)), 'traits': ['Compassionate', 'Artistic', 'Intuitive', 'Gentle']}, | |
| } | |
| # Compatibility scores between signs (1-10) | |
| compatibility = pd.DataFrame( | |
| data=[ | |
| [5,6,7,4,8,5,6,7,8,5,6,7], # Aries with Aries, Taurus, ... Pisces | |
| [6,5,6,7,5,8,7,6,5,8,7,6], | |
| [7,6,5,8,6,7,8,5,6,7,8,5], | |
| [4,7,8,5,7,6,5,8,7,6,5,8], | |
| [8,5,6,7,5,7,6,7,5,8,6,7], | |
| [5,8,7,6,7,5,8,6,7,5,8,6], | |
| [6,7,8,5,6,8,5,7,6,8,7,5], | |
| [7,6,5,8,7,6,7,5,8,6,7,6], | |
| [8,5,6,7,5,7,6,8,5,7,6,8], | |
| [5,8,7,6,8,5,8,6,7,5,8,6], | |
| [6,7,8,5,6,8,7,7,6,8,5,7], | |
| [7,6,5,8,7,6,5,6,8,6,7,5] | |
| ], | |
| index=list(zodiac_traits.keys()), | |
| columns=list(zodiac_traits.keys()) | |
| ) | |
| # Helper to determine zodiac sign from birthdate | |
| def get_zodiac_sign(month: int, day: int) -> str: | |
| for sign, info in zodiac_traits.items(): | |
| start, end = info['dates'] | |
| start_month, start_day = start | |
| end_month, end_day = end | |
| # handle year wrap for Capricorn | |
| if start_month == 12: | |
| if (month == start_month and day >= start_day) or (month == end_month and day <= end_day): | |
| return sign | |
| else: | |
| if (month == start_month and day >= start_day) or (month == end_month and day <= end_day) or (start_month < month < end_month): | |
| return sign | |
| return None | |
| # Streamlit UI | |
| st.title('Zodiac App') | |
| # Horoscope Section | |
| st.header('Get Your Horoscope and Personality Traits') | |
| birthdate = st.date_input("Enter your birthdate:") | |
| if birthdate: | |
| dt = datetime.datetime.strptime(str(birthdate), '%Y-%m-%d') | |
| sign = get_zodiac_sign(dt.month, dt.day) | |
| traits = zodiac_traits[sign]['traits'] | |
| st.subheader(f"Your zodiac sign is: {sign}") | |
| st.write(f"Personality Traits: {', '.join(traits)}") | |
| # Compatibility Section | |
| st.header('Check Compatibility Between Two Zodiac Signs') | |
| sign1 = st.selectbox('Select your sign:', list(zodiac_traits.keys())) | |
| sign2 = st.selectbox('Select partner sign:', list(zodiac_traits.keys())) | |
| if sign1 and sign2: | |
| score = compatibility.at[sign1, sign2] | |
| st.subheader(f"Compatibility Score between {sign1} and {sign2}: {score}") | |
| # Plotting Compatibility Chart | |
| fig, ax = plt.subplots() | |
| ax.bar([sign1 + " & " + sign2], [score]) | |
| ax.set_ylim(0, 10) | |
| ax.set_ylabel('Score (1-10)') | |
| ax.set_title(f'{sign1} & {sign2} Compatibility') | |
| buf = io.BytesIO() | |
| plt.savefig(buf, format='png') | |
| buf.seek(0) | |
| st.image(buf) | |