2021-05-24 23:31:44 +08:00
|
|
|
import gradio as gr
|
|
|
|
|
|
|
|
def tax_calculator(income, marital_status, assets):
|
|
|
|
tax_brackets = [(10, 0), (25, 8), (60, 12), (120, 20), (250, 30)]
|
2022-05-09 12:55:02 +08:00
|
|
|
total_deductible = sum(assets["Cost"])
|
2021-05-24 23:31:44 +08:00
|
|
|
taxable_income = income - total_deductible
|
|
|
|
|
|
|
|
total_tax = 0
|
|
|
|
for bracket, rate in tax_brackets:
|
|
|
|
if taxable_income > bracket:
|
|
|
|
total_tax += (taxable_income - bracket) * rate / 100
|
2022-01-21 21:44:12 +08:00
|
|
|
|
2021-05-24 23:31:44 +08:00
|
|
|
if marital_status == "Married":
|
|
|
|
total_tax *= 0.75
|
|
|
|
elif marital_status == "Divorced":
|
|
|
|
total_tax *= 0.8
|
2022-01-21 21:44:12 +08:00
|
|
|
|
2021-05-24 23:31:44 +08:00
|
|
|
return round(total_tax)
|
|
|
|
|
2022-03-29 06:28:01 +08:00
|
|
|
demo = gr.Interface(
|
2021-05-24 23:31:44 +08:00
|
|
|
tax_calculator,
|
|
|
|
[
|
|
|
|
"number",
|
2022-03-29 06:28:01 +08:00
|
|
|
gr.Radio(["Single", "Married", "Divorced"]),
|
|
|
|
gr.Dataframe(
|
2022-05-09 12:55:02 +08:00
|
|
|
headers=["Item", "Cost"],
|
|
|
|
datatype=["str", "number"],
|
2021-05-24 23:31:44 +08:00
|
|
|
label="Assets Purchased this Year",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
"number",
|
|
|
|
examples=[
|
2022-05-09 12:55:02 +08:00
|
|
|
[10000, "Married", [["Suit", 5000], ["Laptop", 800], ["Car", 1800]]],
|
|
|
|
[80000, "Single", [["Suit", 800], ["Watch", 1800], ["Car", 800]]],
|
2021-05-24 23:31:44 +08:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2022-09-15 23:24:10 +08:00
|
|
|
demo.launch()
|