Spaces:
Sleeping
Sleeping
File size: 2,938 Bytes
1d3b6af 2320a8a 1d3b6af 2320a8a 1d3b6af 2320a8a 1d3b6af 2320a8a 1d3b6af 2320a8a 00ef1a7 1d3b6af 2320a8a 00ef1a7 2320a8a 1d3b6af 2320a8a 00ef1a7 1d3b6af 2320a8a 1d3b6af 2320a8a 1d3b6af 2320a8a 1d3b6af 2320a8a 1d3b6af 00ef1a7 1d3b6af 00ef1a7 |
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 |
import streamlit as st
import pandas as pd
from transformers import T5ForConditionalGeneration, T5Tokenizer
from docx import Document
# Load the generator model (FLAN-T5)
generator_tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
generator_model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large")
# Function to read DOCS files
def read_docs(file):
doc = Document(file)
text = "\n".join([paragraph.text for paragraph in doc.paragraphs])
return text
# Function to process user input and generate financial statements
def generate_financial_statements(file, file_type):
# Read the file based on its type
if file_type == "csv":
df = pd.read_csv(file)
context = df.to_string()
elif file_type == "xlsx":
df = pd.read_excel(file)
context = df.to_string()
elif file_type == "docx":
context = read_docs(file)
else:
st.error("Unsupported file type. Please upload a CSV, Excel, or DOCS file.")
return None
# Define financial statement queries
queries = [
"Generate a journal from the following financial data:",
"Generate a general ledger from the following financial data:",
"Generate an income statement from the following financial data:",
"Generate a balance sheet from the following financial data:",
"Generate a cash flow statement from the following financial data:"
]
# Generate financial statements using the generator model
financial_statements = {}
for query in queries:
# Combine query and context
input_text = f"{query}\n{context}"
# Generate response using the generator model
input_ids = generator_tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True).input_ids
output = generator_model.generate(input_ids, max_length=512)
response = generator_tokenizer.decode(output[0], skip_special_tokens=True)
# Store the result
financial_statements[query] = response
return financial_statements
# Streamlit UI
st.title("Financial Statement Generator")
st.write("Upload your financial data (CSV, Excel, or DOCS) to generate journal, general ledger, income statement, balance sheet, and cash flow statement.")
# File upload
uploaded_file = st.file_uploader("Upload your file", type=["csv", "xlsx", "docx"])
if uploaded_file is not None:
file_type = uploaded_file.name.split(".")[-1].lower() # Ensure lowercase file type
financial_statements = generate_financial_statements(uploaded_file, file_type)
# Display results if financial_statements is not None
if financial_statements is not None:
for statement_type, statement in financial_statements.items():
st.subheader(statement_type)
st.write(statement)
else:
st.error("Failed to generate financial statements. Please check the file type and content.") |