CoolFace
Apppublic

awacke1/Spending-Simulation

sourceHugging Facemitupdated 4y agoView on Hugging Face
1likes
backupapp.py71 linesDownload Raw Back to root
1import streamlit as st2import csv3import base644 5# Define the state populations and family sizes6state_data = {7    'California': {'population': 39538223, 'family_size': 3.3},8    'Texas': {'population': 29145505, 'family_size': 3.4},9    'Florida': {'population': 21538187, 'family_size': 3.0},10    'New York': {'population': 19849399, 'family_size': 3.1},11    'Minnesota': {'population': 5700671, 'family_size': 2.5},12    'Wisconsin': {'population': 5897473, 'family_size': 2.6},13}14 15# Define the state spending data16spending_data = {17    'California': {'education': 2500, 'healthcare': 3000, 'transportation': 1500},18    'Texas': {'education': 2000, 'healthcare': 2500, 'transportation': 1000},19    'Florida': {'education': 1500, 'healthcare': 2000, 'transportation': 750},20    'New York': {'education': 3000, 'healthcare': 3500, 'transportation': 2000},21    'Minnesota': {'education': 1000, 'healthcare': 1500, 'transportation': 500},22    'Wisconsin': {'education': 1250, 'healthcare': 1750, 'transportation': 750},23}24 25# Define the emoji icons26POPULATION_ICON = '๐Ÿ‘ฅ'27FAMILY_SIZE_ICON = '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'28EDUCATION_ICON = '๐Ÿซ'29HEALTHCARE_ICON = '๐Ÿฅ'30TRANSPORTATION_ICON = '๐Ÿš—'31 32def main():33    st.title('State Comparison')34 35    # Consolidate the state data and spending data into a list of dictionaries36    state_list = []37    for state, data in state_data.items():38        state_dict = {39            'state': state,40            'population': data['population'],41            'family_size': data['family_size'],42            'education_spending': spending_data[state]['education'],43            'healthcare_spending': spending_data[state]['healthcare'],44            'transportation_spending': spending_data[state]['transportation']45        }46        state_list.append(state_dict)47 48    # Save the data to a CSV file and provide a download link49    with open('state_data.csv', mode='w', newline='') as file:50        writer = csv.DictWriter(file, fieldnames=['state', 'population', 'family_size', 'education_spending', 'healthcare_spending', 'transportation_spending'])51        writer.writeheader()52        for state in state_list:53            writer.writerow(state)54    with open('state_data.csv', mode='rb') as file:55        b64 = base64.b64encode(file.read()).decode('utf-8')56    st.markdown(f'<a href="data:file/csv;base64,{b64}" download="state_data.csv">Download State Data CSV File</a>', unsafe_allow_html=True)57 58    # Display state populations and family sizes59    st.header('Population and Family Size')60    for state, data in state_data.items():61        st.subheader(f'{POPULATION_ICON} {state}')62    st.write(f'Population: {data["population"]}')63    st.write(f'Family Size: {data["family_size"]}')64 65# Display state spending data66st.header('State Spending')67for state, data in spending_data.items():68    st.subheader(state)69    st.write(f'{EDUCATION_ICON} Education: {data["education"]}')70    st.write(f'{HEALTHCARE_ICON} Healthcare: {data["healthcare"]}')71    st.write(f'{TRANSPORTATION_ICON} Transportation: {data["transportation"]}')