Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Salary Distributor Function
|
| 5 |
+
def salary_distributor(gross, categories_input):
|
| 6 |
+
try:
|
| 7 |
+
categories = []
|
| 8 |
+
for line in categories_input.strip().split("\n"):
|
| 9 |
+
name, mode, value = line.split(",")
|
| 10 |
+
value = float(value)
|
| 11 |
+
amount = (gross * value / 100) if mode.strip() == "%" else value
|
| 12 |
+
categories.append({
|
| 13 |
+
"Category": name.strip(),
|
| 14 |
+
"Mode": mode.strip(),
|
| 15 |
+
"Value": value,
|
| 16 |
+
"Amount": round(amount, 2)
|
| 17 |
+
})
|
| 18 |
+
|
| 19 |
+
df = pd.DataFrame(categories)
|
| 20 |
+
total_allocated = round(df["Amount"].sum(), 2)
|
| 21 |
+
remaining = round(gross - total_allocated, 2)
|
| 22 |
+
|
| 23 |
+
return df, total_allocated, remaining
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return pd.DataFrame(), 0, f"Error: {e}"
|
| 26 |
+
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("## Salary Distributor Calculator")
|
| 29 |
+
|
| 30 |
+
with gr.Row():
|
| 31 |
+
gross_salary = gr.Number(label="Gross Salary", value=1000)
|
| 32 |
+
categories_input = gr.Textbox(
|
| 33 |
+
label="Categories (name, mode, value)",
|
| 34 |
+
value="Taxes,%,20\nSavings,%,10\nRent,fixed,300\nBills,%,5",
|
| 35 |
+
lines=6
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
output_table = gr.Dataframe(headers=["Category", "Mode", "Value", "Amount"], datatype=["str", "str", "number", "number"])
|
| 39 |
+
total_output = gr.Number(label="Total Allocated")
|
| 40 |
+
remaining_output = gr.Number(label="Remaining")
|
| 41 |
+
|
| 42 |
+
run_btn = gr.Button("Calculate")
|
| 43 |
+
run_btn.click(fn=salary_distributor, inputs=[gross_salary, categories_input], outputs=[output_table, total_output, remaining_output])
|
| 44 |
+
|
| 45 |
+
demo.launch()
|