Spaces:
Sleeping
Sleeping
File size: 2,846 Bytes
1d3b6af |
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
import os
from transformers import T5ForConditionalGeneration, T5Tokenizer
import groq
# Initialize Groq API
groq_client = groq.Client(api_key="your_groq_api_key")
# Load RAG components
retriever_tokenizer = DPRContextEncoderTokenizer.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base")
retriever_model = DPRContextEncoder.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base")
generator_tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
generator_model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large")
# Function to process user input and generate financial statements
def generate_financial_statements(file, file_type):
# Read the file
if file_type == "csv":
df = pd.read_csv(file)
elif file_type == "excel":
df = pd.read_excel(file)
else:
st.error("Unsupported file type. Please upload a CSV or Excel file.")
return
# Convert the data into a context string
context = df.to_string()
# 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 RAG
financial_statements = {}
for query in queries:
# Combine query and context
input_text = f"{query}\n{context}"
# Retrieve relevant information (optional, if using a retriever)
input_ids = retriever_tokenizer(input_text, return_tensors="pt").input_ids
retrieved_context = retriever_model(input_ids)
# Generate response using the generator model
input_ids = generator_tokenizer(input_text, return_tensors="pt").input_ids
output = generator_model.generate(input_ids)
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 or Excel) 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"])
if uploaded_file is not None:
file_type = uploaded_file.name.split(".")[-1]
financial_statements = generate_financial_statements(uploaded_file, file_type)
# Display results
for statement_type, statement in financial_statements.items():
st.subheader(statement_type)
st.write(statement) |