Spaces:
Running
Running
File size: 5,253 Bytes
add7229 1407118 add7229 1407118 add7229 1407118 add7229 1407118 add7229 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
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)
|