How boulkadi/finance_analysis_cih works
Project Type and Purpose
• Finance_Analysis_CIH is a full-stack, data-centric, interactive analytics application built in Python with Streamlit as the UI layer.
• It ingests PDF financial reports from Banque CIH, extracts and cleans tabular/text data, visualizes trends, and provides an AI-powered Q&A interface using LangChain (with Google Generative AI and Hugging Face backends).
File Structure Analysis
• Top-level “stream.py”: the main Streamlit app orchestrating UI, data loading, analysis, visualization, and AI queries.
• “rapports_CIH/”: raw PDF inputs (2013–2024).
• “output/”: processed CSV/text outputs.
• “.streamlit/secrets.toml”: credentials for external AI APIs.
• “requirements.txt”: dependencies (Streamlit, LangChain, PDF parsers, plotting libs).
• “test.ipynb”: exploratory notebook likely for prototyping extraction/analysis.
Core Components
a. Streamlit Frontend
• UI widgets (file selector, parameters, chart panels, Q&A chat).
• Initiates user actions (upload, select report, ask question).
b. PDF Ingestion & Extraction Module
• Locates PDFs in rapports_CIH/.
• Uses a PDF parser (e.g., pdfplumber or PyPDF2) + text cleaners to produce raw text/tables.
c. Data Processing & Cleaning Module
• Cleans, normalizes, aggregates financial tables.
• Writes intermediate CSV/text to output/.
d. Visualization Module
• Leverages Plotly/Matplotlib/Altair via Streamlit to render interactive charts and tables.
e. AI Q&A Module (LangChain)
• Loads cleaned text segments.
• Sends context + user query to LLM endpoints (Google GenAI / HuggingFace).
• Receives answer and streams back to UI.
f. External Services
• Google Generative AI API
• Hugging Face Inference API
g. Storage
• Local filesystem for PDFs & CSVs
• .streamlit/secrets.toml for credentials
Relationships and Data Flow
• User → Streamlit UI
• UI → PDF Ingestion → Extraction → Data Processing
• Processed data → Storage & Visualization
• User Q&A → AI Q&A Module → External LLM APIs → Response → UI
Architectural Patterns and Principles
• Monolithic modular structure: one Python service subdivided into logical modules.
• Separation of concerns: ingestion, processing, visualization, AI querying.
• Extensibility points: swapping PDF parsers or LLM backends via config.
• Configuration management via .streamlit/secrets.toml.