Spaces:
Running
Running
File size: 4,051 Bytes
d3dfed6 b793268 04f21eb b793268 04f21eb b793268 04f21eb b793268 c60877b b793268 d3dfed6 b793268 d3dfed6 b793268 c78bdd0 b793268 c60877b b793268 c60877b b793268 c78bdd0 b793268 04f21eb b793268 c78bdd0 c60877b b793268 c78bdd0 d3dfed6 |
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 |
import gradio as gr
def calculate(input_value: float, calculation_type: str) -> dict:
vat_rate = 0.07
withholding_rate = 0.03
if calculation_type == "base_amount":
base = input_value
vat = base * vat_rate
total_after_vat = base + vat
withholding_tax = base * withholding_rate
net_amount = total_after_vat - withholding_tax
elif calculation_type == "total_after_vat":
total_after_vat = input_value
base = total_after_vat / (1 + vat_rate)
vat = total_after_vat - base
withholding_tax = base * withholding_rate
net_amount = total_after_vat - withholding_tax
elif calculation_type == "net_amount":
net_amount = input_value
base = net_amount / (1 + vat_rate - withholding_rate)
vat = base * vat_rate
total_after_vat = base + vat
withholding_tax = base * withholding_rate
elif calculation_type == "withholding_tax":
withholding_tax = input_value
base = withholding_tax / withholding_rate
vat = base * vat_rate
total_after_vat = base + vat
net_amount = total_after_vat - withholding_tax
return {
"base_amount": base,
"vat": vat,
"total_after_vat": total_after_vat,
"withholding_tax": withholding_tax,
"net_amount": net_amount
}
def format_output(value: float) -> str:
return f"{value:,.2f} บาท"
def update_outputs(input_value, calculation_type):
if not input_value:
return ["", "", "", "", ""]
results = calculate(float(input_value), calculation_type)
return [
format_output(results["base_amount"]),
format_output(results["vat"]),
format_output(results["total_after_vat"]),
format_output(results["withholding_tax"]),
format_output(results["net_amount"])
]
with gr.Blocks(title="Tax Calculator") as demo:
gr.Markdown("# 📊 เครื่องคิดเลขภาษี 7% และหัก ณ ที่จ่าย 3%")
gr.Markdown("## ⚙️ ป้อนข้อมูลและเลือกประเภทการคำนวณ")
with gr.Row():
calculation_type = gr.Dropdown(
choices=[
("จำนวนเงินต้น (ก่อนภาษี)", "base_amount"),
("ยอดหลัง VAT (รวม VAT แล้ว)", "total_after_vat"),
("ยอดสุทธิ (หลังหัก ณ ที่จ่าย)", "net_amount"),
("จำนวนเงินหัก ณ ที่จ่าย", "withholding_tax")
],
label="ประเภทการคำนวณ",
value="base_amount"
)
input_value = gr.Number(
label="ป้อนยอดเงิน",
precision=2,
minimum=0
)
gr.Markdown("## 📜 ผลลัพธ์การคำนวณ")
with gr.Row():
with gr.Column():
gr.Markdown("### เงินต้น (ก่อน VAT)")
base_amount = gr.Textbox()
with gr.Column():
gr.Markdown("### VAT 7%")
vat = gr.Textbox()
with gr.Column():
gr.Markdown("### ยอดหลัง VAT")
total_after_vat = gr.Textbox()
with gr.Column():
gr.Markdown("### หัก ณ ที่จ่าย 3%")
withholding_tax = gr.Textbox()
with gr.Column():
gr.Markdown("### ยอดสุทธิ")
net_amount = gr.Textbox()
input_value.change(
update_outputs,
[input_value, calculation_type],
[base_amount, vat, total_after_vat, withholding_tax, net_amount]
)
calculation_type.change(
update_outputs,
[input_value, calculation_type],
[base_amount, vat, total_after_vat, withholding_tax, net_amount]
)
demo.launch() |