-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
149 lines (134 loc) · 4.81 KB
/
app.py
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import streamlit as st
from config import load_config
from constants import TEAL_ACCENT, MARGIN
from ui.basic import (
render_state_selector,
render_income_input,
render_personal_info,
render_itemized_deductions,
render_notes,
)
from ui.donations import render_initial_donation, render_policyengine_donate
from ui.tax_results import render_tax_results
from ui.target_donation import render_target_donation_section
from calculations.tax import (
calculate_donation_metrics,
calculate_donation_effects,
)
from tax_info import display_tax_programs
from situation import create_situation
def main():
st.set_page_config(page_title="GiveCalc", page_icon="💝")
# Inject custom CSS with Roboto font
st.markdown(
"""
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900&display=swap');
html, body, [class*="css"] {
font-family: 'Roboto', sans-serif;
}
div[data-testid="stToolbar"] {
visibility: hidden;
}
footer {
visibility: hidden;
}
</style>
""",
unsafe_allow_html=True,
)
st.markdown(
f"""
<h1 style="font-family: Roboto;">
<span style="color: {TEAL_ACCENT}; font-weight: bold;">Give</span><span style="color: {TEAL_ACCENT}; font-weight: normal;">Calc</span>
<span style="color: #BDBDBD; font-weight: normal;"> by PolicyEngine</span>
</h1>
""",
unsafe_allow_html=True,
)
st.markdown(
f"Calculate how charitable giving affects your taxes. [Read our explainer to learn more.](https://policyengine.org/us/research/givecalc)"
)
st.divider()
# Load configuration
config = load_config()
# Basic information
state, in_nyc = render_state_selector(config["states"])
income = render_income_input()
is_married, num_children = render_personal_info()
deductions = render_itemized_deductions()
donation_amount = render_initial_donation(income)
donation_in_mind = st.checkbox(
"Would you like to target a donation level based on net income reduction?"
)
if donation_in_mind:
st.expander("Calculate a target donation")
# Add radio button for percentage vs dollar amount
reduction_type = st.radio(
"How would you like to reduce your net income?",
options=["Percentage", "Dollar amount"],
horizontal=True,
index=0, # Default to percentage
)
# Condensed input field for reduction amount with one decimal point
reduction_amount = st.number_input(
f"Enter reduction amount ({'%' if reduction_type == 'Percentage' else '$'}):",
min_value=0.0, # Always use float for min_value
max_value=(
100.0 if reduction_type == "Percentage" else float(income)
), # Convert income to float
value=(
10.0 if reduction_type == "Percentage" else float(min(1000, income))
), # Convert to float
step=(
0.1 if reduction_type == "Percentage" else 100.0
), # Use float for step values
format="%.1f", # Consistent format for both cases
help=f"Enter the reduction in {'percentage' if reduction_type == 'Percentage' else 'dollars'}.",
)
if st.button("Calculate tax implications", type="primary"):
# Calculate baseline metrics once
situation = create_situation(
income,
is_married=is_married,
state_code=state,
in_nyc=in_nyc,
num_children=num_children,
**deductions,
)
baseline_metrics = calculate_donation_metrics(situation, donation_amount=0)
current_donation_metrics = calculate_donation_metrics(
situation, donation_amount
)
current_donation_plus100_metrics = calculate_donation_metrics(
situation, donation_amount + MARGIN
)
df = calculate_donation_effects(situation)
# Render main sections
render_tax_results(
df,
baseline_metrics,
income,
donation_amount,
current_donation_metrics,
current_donation_plus100_metrics,
)
if donation_in_mind:
render_target_donation_section(
df,
baseline_metrics,
income,
donation_amount,
current_donation_metrics,
situation,
reduction_amount,
reduction_type,
)
# Display tax program information
st.divider()
display_tax_programs(config, state)
# Display notes
render_notes()
render_policyengine_donate()
if __name__ == "__main__":
main()