Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	| 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) |