Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ def generate_financial_statements(file, mapping):
|
|
| 15 |
df = pd.read_excel(file, usecols=['Account', 'Balance'])
|
| 16 |
df['Account'] = df['Account'].astype(str).fillna('')
|
| 17 |
df['Balance'] = df['Balance'] / 1000 # Convert values to thousands (000)
|
| 18 |
-
|
| 19 |
# Apply account mapping to categorize accounts
|
| 20 |
df['Category'] = df['Account'].str.lower().map(mapping).fillna('Other')
|
| 21 |
|
|
@@ -23,17 +23,16 @@ def generate_financial_statements(file, mapping):
|
|
| 23 |
revenue = df[df['Category'] == 'Revenue']['Balance'].sum()
|
| 24 |
cost_of_sales = df[df['Category'] == 'Cost of Sales']['Balance'].sum()
|
| 25 |
gross_profit = revenue - cost_of_sales
|
| 26 |
-
|
| 27 |
-
other_income = df[df['Category'] == 'Other']['Balance'].sum()
|
| 28 |
operating_expenses = df[df['Category'] == 'Operating Expenses']['Balance'].sum()
|
| 29 |
-
operating_profit = gross_profit
|
| 30 |
-
|
| 31 |
finance_costs = df[df['Category'] == 'Finance Costs']['Balance'].sum()
|
| 32 |
profit_before_tax = operating_profit - finance_costs
|
| 33 |
-
|
| 34 |
tax_expense = df[df['Category'] == 'Tax Expense']['Balance'].sum()
|
| 35 |
profit_for_the_year = profit_before_tax - tax_expense
|
| 36 |
-
|
| 37 |
# Generate the income statement with formatting
|
| 38 |
income_statement = f"""
|
| 39 |
INCOME STATEMENT (in 000s)
|
|
@@ -43,7 +42,6 @@ def generate_financial_statements(file, mapping):
|
|
| 43 |
------------------------------------------------
|
| 44 |
Gross Profit: {gross_profit:,.2f}
|
| 45 |
|
| 46 |
-
Other Income: {other_income:,.2f}
|
| 47 |
Operating Expenses: ({operating_expenses:,.2f})
|
| 48 |
------------------------------------------------
|
| 49 |
Operating Profit: {operating_profit:,.2f}
|
|
@@ -86,4 +84,4 @@ with gr.Blocks() as demo:
|
|
| 86 |
|
| 87 |
# Launch the Gradio app
|
| 88 |
if __name__ == "__main__":
|
| 89 |
-
demo.launch(share=True
|
|
|
|
| 15 |
df = pd.read_excel(file, usecols=['Account', 'Balance'])
|
| 16 |
df['Account'] = df['Account'].astype(str).fillna('')
|
| 17 |
df['Balance'] = df['Balance'] / 1000 # Convert values to thousands (000)
|
| 18 |
+
|
| 19 |
# Apply account mapping to categorize accounts
|
| 20 |
df['Category'] = df['Account'].str.lower().map(mapping).fillna('Other')
|
| 21 |
|
|
|
|
| 23 |
revenue = df[df['Category'] == 'Revenue']['Balance'].sum()
|
| 24 |
cost_of_sales = df[df['Category'] == 'Cost of Sales']['Balance'].sum()
|
| 25 |
gross_profit = revenue - cost_of_sales
|
| 26 |
+
|
|
|
|
| 27 |
operating_expenses = df[df['Category'] == 'Operating Expenses']['Balance'].sum()
|
| 28 |
+
operating_profit = gross_profit - operating_expenses
|
| 29 |
+
|
| 30 |
finance_costs = df[df['Category'] == 'Finance Costs']['Balance'].sum()
|
| 31 |
profit_before_tax = operating_profit - finance_costs
|
| 32 |
+
|
| 33 |
tax_expense = df[df['Category'] == 'Tax Expense']['Balance'].sum()
|
| 34 |
profit_for_the_year = profit_before_tax - tax_expense
|
| 35 |
+
|
| 36 |
# Generate the income statement with formatting
|
| 37 |
income_statement = f"""
|
| 38 |
INCOME STATEMENT (in 000s)
|
|
|
|
| 42 |
------------------------------------------------
|
| 43 |
Gross Profit: {gross_profit:,.2f}
|
| 44 |
|
|
|
|
| 45 |
Operating Expenses: ({operating_expenses:,.2f})
|
| 46 |
------------------------------------------------
|
| 47 |
Operating Profit: {operating_profit:,.2f}
|
|
|
|
| 84 |
|
| 85 |
# Launch the Gradio app
|
| 86 |
if __name__ == "__main__":
|
| 87 |
+
demo.launch() # Set share=True only for public access if needed
|