geeksiddhant commited on
Commit
04a9cde
·
verified ·
1 Parent(s): 819cab0

create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Define the tax calculator function
4
+ def tax_calculator(income, marital_status, assets):
5
+ tax_brackets = [(10, 0), (25, 8), (60, 12), (120, 20), (250, 30)]
6
+ total_deductible = sum(assets["Cost"])
7
+ taxable_income = income - total_deductible
8
+
9
+ total_tax = 0
10
+ for bracket, rate in tax_brackets:
11
+ if taxable_income > bracket:
12
+ total_tax += (taxable_income - bracket) * rate / 100
13
+
14
+ if marital_status == "Married":
15
+ total_tax *= 0.75
16
+ elif marital_status == "Divorced":
17
+ total_tax *= 0.8
18
+
19
+ return round(total_tax)
20
+
21
+ # Create the Gradio Interface
22
+ demo = gr.Interface(
23
+ tax_calculator,
24
+ [
25
+ "number", # Input for income
26
+ gr.Radio(["Single", "Married", "Divorced"]), # Input for marital status
27
+ gr.Dataframe(
28
+ headers=["Item", "Cost"],
29
+ datatype=["str", "number"],
30
+ label="Assets Purchased this Year",
31
+ ), # Input for assets
32
+ ],
33
+ "number", # Output for total tax
34
+ examples=[
35
+ [10000, "Married", [["Suit", 5000], ["Laptop", 800], ["Car", 1800]]],
36
+ [80000, "Single", [["Suit", 800], ["Watch", 1800], ["Car", 800]]],
37
+ ], # Examples for the user to try
38
+ )
39
+
40
+ # Launch the Gradio app
41
+ demo.launch(show_error=True)