darsoarafa commited on
Commit
d721393
·
verified ·
1 Parent(s): 49c33e8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -0
app.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import openpyxl
4
+ from io import BytesIO
5
+ import re
6
+
7
+ def parse_assumptions(assumptions_text):
8
+ # Default values
9
+ params = {
10
+ 'initial_investment': 1000000000, # Rp 1M
11
+ 'annual_revenue': 500000000, # Rp 500jt/tahun
12
+ 'revenue_growth': 0.05, # 5% per tahun
13
+ 'operating_cost': 300000000, # Rp 300jt/tahun
14
+ 'cost_growth': 0.03, # 3% per tahun
15
+ 'depreciation_years': 7, # Umur ekonomis mesin
16
+ 'tax_rate': 0.25, # Pajak 25%
17
+ 'working_capital': 50000000 # Modal kerja Rp 50jt
18
+ }
19
+
20
+ # Parsing assumptions from text
21
+ patterns = {
22
+ 'initial_investment': r'Initial Investment[\s:]*Rp\s*([\d,.]+)',
23
+ 'annual_revenue': r'Annual Revenue[\s:]*Rp\s*([\d,.]+)',
24
+ 'revenue_growth': r'Revenue Growth[\s:]*([\d.]+)\%',
25
+ 'operating_cost': r'Operating Cost[\s:]*Rp\s*([\d,.]+)',
26
+ 'cost_growth': r'Cost Growth[\s:]*([\d.]+)\%',
27
+ 'depreciation_years': r'Depreciation Years[\s:]*(\d+)',
28
+ 'tax_rate': r'Tax Rate[\s:]*([\d.]+)\%',
29
+ 'working_capital': r'Working Capital[\s:]*Rp\s*([\d,.]+)'
30
+ }
31
+
32
+ for key, pattern in patterns.items():
33
+ match = re.search(pattern, assumptions_text, re.IGNORECASE)
34
+ if match:
35
+ value = match.group(1)
36
+ if key in ['initial_investment', 'annual_revenue', 'operating_cost', 'working_capital']:
37
+ value = float(value.replace(',', '').replace('.', ''))
38
+ elif key in ['revenue_growth', 'cost_growth', 'tax_rate']:
39
+ value = float(value) / 100
40
+ else:
41
+ value = float(value)
42
+ params[key] = value
43
+
44
+ return params
45
+
46
+ def generate_financials(assumptions_text):
47
+ params = parse_assumptions(assumptions_text)
48
+ years = range(1, 8)
49
+
50
+ # Initialize data structures
51
+ profit_loss = []
52
+ cashflow = []
53
+
54
+ # Calculate financials
55
+ initial_investment = params['initial_investment']
56
+ working_capital = params['working_capital']
57
+ depreciation = initial_investment / params['depreciation_years']
58
+
59
+ revenue = params['annual_revenue']
60
+ operating_cost = params['operating_cost']
61
+
62
+ for year in years:
63
+ # Profit Loss
64
+ revenue *= (1 + params['revenue_growth'])
65
+ operating_cost *= (1 + params['cost_growth'])
66
+
67
+ ebitda = revenue - operating_cost
68
+ ebit = ebitda - depreciation
69
+ tax = max(ebit * params['tax_rate'], 0)
70
+ net_income = ebit - tax
71
+
72
+ profit_loss.append({
73
+ 'Year': year,
74
+ 'Revenue': revenue,
75
+ 'Operating Cost': operating_cost,
76
+ 'EBITDA': ebitda,
77
+ 'Depreciation': depreciation,
78
+ 'EBIT': ebit,
79
+ 'Tax': tax,
80
+ 'Net Income': net_income
81
+ })
82
+
83
+ # Cashflow
84
+ cash_in = revenue
85
+ cash_out = operating_cost + tax
86
+ if year == 1:
87
+ cash_out += initial_investment + working_capital
88
+ if year == 7:
89
+ cash_in += working_capital # Recovery of working capital
90
+ net_cashflow = cash_in - cash_out
91
+
92
+ cashflow.append({
93
+ 'Year': year,
94
+ 'Cash In': cash_in,
95
+ 'Cash Out': cash_out,
96
+ 'Net Cashflow': net_cashflow
97
+ })
98
+
99
+ # Create DataFrames
100
+ pl_df = pd.DataFrame(profit_loss)
101
+ cf_df = pd.DataFrame(cashflow)
102
+
103
+ # Create Excel file
104
+ output = BytesIO()
105
+ with pd.ExcelWriter(output, engine='openpyxl') as writer:
106
+ pl_df.to_excel(writer, sheet_name='Profit_Loss', index=False)
107
+ cf_df.to_excel(writer, sheet_name='Cashflow', index=False)
108
+
109
+ output.seek(0)
110
+ return output, 'financial_projections.xlsx'
111
+
112
+ # Gradio interface
113
+ with gr.Blocks() as demo:
114
+ gr.Markdown("# Financial Projections for Tea Production Machine Replacement")
115
+ assumptions = gr.Textbox(
116
+ label="Input Assumptions",
117
+ placeholder="""Example format:
118
+ Initial Investment: Rp 1,000,000,000
119
+ Annual Revenue: Rp 500,000,000
120
+ Revenue Growth: 5%
121
+ Operating Cost: Rp 300,000,000
122
+ Cost Growth: 3%
123
+ Depreciation Years: 7
124
+ Tax Rate: 25%
125
+ Working Capital: Rp 50,000,000""",
126
+ lines=10
127
+ )
128
+ generate_button = gr.Button("Generate Financials")
129
+ output_file = gr.File(label="Download Excel File")
130
+
131
+ generate_button.click(
132
+ fn=generate_financials,
133
+ inputs=assumptions,
134
+ outputs=[output_file]
135
+ )
136
+
137
+ demo.launch()