Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Function to read trial balance and prepare financial statements
|
| 5 |
+
def generate_financial_statements(file):
|
| 6 |
+
# Read the Excel file
|
| 7 |
+
df = pd.read_excel(file)
|
| 8 |
+
|
| 9 |
+
# Assuming the trial balance has columns: 'Account', 'Debit', 'Credit'
|
| 10 |
+
if 'Account' not in df.columns or 'Debit' not in df.columns or 'Credit' not in df.columns:
|
| 11 |
+
return "Invalid file format. Please ensure the columns are 'Account', 'Debit', and 'Credit'."
|
| 12 |
+
|
| 13 |
+
# Calculate totals
|
| 14 |
+
total_debit = df['Debit'].sum()
|
| 15 |
+
total_credit = df['Credit'].sum()
|
| 16 |
+
|
| 17 |
+
# Create Profit & Loss Statement
|
| 18 |
+
pnl = df[df['Debit'] > 0].copy()
|
| 19 |
+
pnl['Type'] = 'Expense'
|
| 20 |
+
pnl.loc[pnl['Credit'] > 0, 'Type'] = 'Income'
|
| 21 |
+
|
| 22 |
+
pnl_summary = pnl.groupby('Type')['Debit', 'Credit'].sum().reset_index()
|
| 23 |
+
|
| 24 |
+
# Create Balance Sheet
|
| 25 |
+
balance_sheet = df.groupby(df['Account'].str.contains('Asset|Liability|Equity')).agg({'Debit': 'sum', 'Credit': 'sum'}).reset_index()
|
| 26 |
+
balance_sheet.columns = ['Type', 'Debit', 'Credit']
|
| 27 |
+
|
| 28 |
+
return pnl_summary, balance_sheet
|
| 29 |
+
|
| 30 |
+
# Gradio interface
|
| 31 |
+
def gradio_interface(file):
|
| 32 |
+
pnl_summary, balance_sheet = generate_financial_statements(file)
|
| 33 |
+
return pnl_summary.to_string(), balance_sheet.to_string()
|
| 34 |
+
|
| 35 |
+
# Launch the Gradio app
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn=gradio_interface,
|
| 38 |
+
inputs=gr.inputs.File(label="Upload Trial Balance Excel File"),
|
| 39 |
+
outputs=[
|
| 40 |
+
gr.outputs.Textbox(label="Profit & Loss Statement"),
|
| 41 |
+
gr.outputs.Textbox(label="Balance Sheet")
|
| 42 |
+
],
|
| 43 |
+
title="Financial Statement Generator",
|
| 44 |
+
description="Upload a trial balance Excel file to generate Profit & Loss account and Balance Sheet."
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
iface.launch()
|