ubaid1234 commited on
Commit
f7db7b6
·
verified ·
1 Parent(s): 69fc14d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def calculate_tvm(initial_investment, annual_revenue, annual_opex, tax_rate, years, discount_rate):
4
+ # Convert percentages to decimals
5
+ i = discount_rate / 100
6
+ t_rate = tax_rate / 100
7
+
8
+ annual_cash_flow = (annual_revenue - annual_opex) * (1 - t_rate)
9
+
10
+ # Calculate NPV
11
+ npv = -initial_investment
12
+ for t in range(1, int(years) + 1):
13
+ npv += annual_cash_flow / ((1 + i) ** t)
14
+
15
+ # Calculate Simple Payback Period
16
+ if annual_cash_flow > 0:
17
+ payback = initial_investment / annual_cash_flow
18
+ else:
19
+ payback = float('inf')
20
+
21
+ return (
22
+ f"Resulting NPV: ${round(npv, 2):,}",
23
+ f"Annual After-Tax Cash Flow: ${round(annual_cash_flow, 2):,}",
24
+ f"Simple Payback Period: {round(payback, 2)} years"
25
+ )
26
+
27
+ # Define the Interface
28
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
29
+ gr.Markdown("# 🧪 Chemical Engineering TVM Calculator")
30
+ gr.Markdown("Evaluate the economic viability of process equipment or plant expansions.")
31
+
32
+ with gr.Row():
33
+ with gr.Column():
34
+ inv = gr.Number(label="Initial Investment ($)", value=1000000)
35
+ rev = gr.Number(label="Annual Revenue ($)", value=500000)
36
+ opex = gr.Number(label="Annual OPEX ($)", value=150000)
37
+ with gr.Column():
38
+ tax = gr.Slider(0, 50, value=21, label="Tax Rate (%)")
39
+ years = gr.Slider(1, 30, value=10, step=1, label="Project Life (Years)")
40
+ disc = gr.Slider(0, 20, value=10, label="Discount Rate / MARR (%)")
41
+
42
+ btn = gr.Button("Calculate Economic Viability", variant="primary")
43
+
44
+ with gr.Row():
45
+ out_npv = gr.Textbox(label="Net Present Value (NPV)")
46
+ out_cash = gr.Textbox(label="Annual Cash Flow")
47
+ out_payback = gr.Textbox(label="Payback Period")
48
+
49
+ btn.click(
50
+ fn=calculate_tvm,
51
+ inputs=[inv, rev, opex, tax, years, disc],
52
+ outputs=[out_npv, out_cash, out_payback]
53
+ )
54
+
55
+ if __name__ == "__main__":
56
+ demo.launch()