import streamlit as st import pandas as pd import datetime import matplotlib.pyplot as plt import numpy as np 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 # Function to create radar chart def create_radar_chart(traits, values, sign): num_vars = len(traits) # Compute the angle for each trait (360 degrees divided by number of traits) angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist() # The plot needs to be circular, so we repeat the first value to close the loop values += values[:1] angles += angles[:1] # Create the radar chart fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True)) # Plot the data ax.fill(angles, values, color='blue', alpha=0.25) ax.plot(angles, values, color='blue', linewidth=2) # Outline of the chart # Set the labels for each axis (the traits) ax.set_yticklabels([]) # Remove the radial ticks ax.set_xticks(angles[:-1]) # Set the ticks for each trait ax.set_xticklabels(traits, color='black', fontsize=12) # Add the title ax.set_title(f'{sign} Personality Traits', size=14, color='black', fontweight='bold') # Show the radar chart return fig # Streamlit UI st.title('Zodiac Matcher') # 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)}") # Display Radar Chart for Zodiac Sign trait_values = [9, 10, 8, 9] # Example trait values for the radar chart (can be adjusted) fig = create_radar_chart(traits, trait_values, sign) buf = io.BytesIO() fig.savefig(buf, format='png') buf.seek(0) st.image(buf) # 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)