How thomasruegg/generative-excel-data-assistant works
1. Overall shape
- GEDA is a single Python application, launched from gui.py, that combines a Gradio chat UI, Excel ingestion/normalization, an LLM-based function-calling orchestrator, and a library of domain-specific data operations.
- The repo is organized around one core pattern: the user speaks in natural language, the system selects a safe predefined Python function, executes it on one or more Excel files, and returns text, tables, charts, or a rewritten workbook.
2. User-facing boundary
- The only interactive front door is the Gradio interface.
- It handles chat messages, file uploads, model selection, and file download of edited Excel outputs.
- The presence of .gradio/certificate.pem suggests the UI can run with local HTTPS support, but the main architectural point is that Gradio is the presentation and session boundary, not a separate backend service.
3. Excel file ingestion
- Uploaded spreadsheets are first inspected to detect the real header row and any title/description text above it.
- Those files are then loaded into Pandas DataFrames for downstream querying and transformation.
- data_loader.py and excel_preparations.py appear to own this preprocessing boundary, turning messy Excel inputs into structured in-memory data that the rest of the system can use.
4. Metadata extraction and caching
- After upload, GEDA generates per-file metadata such as data type, country code, year range, standardized column mapping, and a checksum.
- This metadata is cached locally as JSON so the system does not need to re-infer file meaning on every request.
- The checksum is the invalidation mechanism: if the file changes, metadata is refreshed.
- This layer is important because it is what allows the assistant to identify the right file among many similar spreadsheets.
5. File mapping for Gradio downloads
- Because Gradio stores uploaded files in temp locations, the app maintains a file-path mapping so edited workbooks can be rediscovered and exposed back through the UI.
- This is a small but critical infrastructure boundary: it connects transient upload paths to persistent user-visible download behavior.
6. Function catalog as the core capability layer
- The real “product logic” lives in functions.py.
- These functions implement supported tasks such as querying cells, aggregating sales/cost data, comparing time ranges, creating new columns, plotting, currency conversion, and editing Excel files.
- The design is intentionally controlled: the assistant can only do what is encoded as a function, which limits unsafe or unintended data manipulation.
7. LLM orchestration and function calling
- function_calling_agent.py is the central orchestrator.
- It takes the user prompt, retrieves the most relevant candidate functions, passes those candidates plus parameter descriptions to the LLM, and then executes the selected function.
- prompt.txt likely contains the system or tool-selection prompt used to steer model behavior.
- The architecture is therefore “LLM as router,” not “LLM as free-form analyst.”
8. Retrieval-Augmented Generation for function selection
- GEDA uses RAG to narrow a large function catalog down to the top 5 likely matches before asking the LLM to choose.
- The README describes FAISS as the vector-store/retrieval engine for function names and descriptions.
- This retrieval step is a key architectural boundary: it keeps prompts small, reduces hallucinated tool calls, and makes the assistant scalable as more functions are added.
9. Model abstraction
- llm_factory.py likely hides provider differences behind a common interface.
- The repo supports multiple backends: OpenAI gpt-4o-mini, hosted models on llmhub, and local Ollama models such as llama3.2.
- This makes the model layer interchangeable, while the rest of the system stays focused on tool execution rather than provider-specific APIs.
10. Data processing and output generation
- Once a function is selected, it operates on Pandas data and may produce:
- text answers,
- tabular results,
- charts/plots,
- or modified Excel files.
- Excel editing uses XlsxWriter when a workbook must be rewritten.
- Plotting is a first-class output type, and the README emphasizes interactive plots as part of the user experience.
11. External service dependencies
- Currency conversion is supported through an external web API, so the assistant is not entirely self-contained for financial normalization.
- LLM calls may go to OpenAI, llmhub, or a locally running Ollama server, depending on configuration in .env.
- These external dependencies affect latency, cost, and offline capability, so they are meaningful architectural components.
12. Local filesystem as the main state store
- There is no sign of a separate database or server-side persistence layer.
- State is primarily local: uploaded Excel files, cached metadata JSON, mapping files, and model/config environment variables.
- That makes the app lightweight and easy to run, but also means cache/session state is ephemeral across restarts.
13. Repository content and sample data
- The data/ folder contains representative Excel workbooks for sales and material cost/inventory across multiple countries and years.
- These samples are likely used for development, demos, and testing the file-identification logic against realistic spreadsheet variants.
- data_notice.txt suggests there are usage or provenance constraints on the dataset.
14. End-to-end flow to diagram
- The main data flow is: upload Excel files → detect structure and create DataFrames → infer/cache metadata → user prompt enters chat → retrieve top candidate functions via RAG → LLM selects a function and parameters → function runs on the relevant file(s) → result is rendered or saved → user optionally downloads the edited workbook.
- In an architecture diagram, the critical boundaries are: UI, file ingestion/metadata, function retrieval, LLM routing, execution/processing, and output/download handling.
Main entry points: function_calling_agent.py Agent · functions.py Functions · llm_factory.py Model Factory · gui.py Gradio UI
Components 17
Presentation
Gradio chat interface and file download boundary
Excel Intake
Spreadsheet loading, structure detection, and metadata caching
- Loader · Loads uploaded spreadsheets into DataFrames
data_loader.py - Prep · Finds real headers, title text, and cleans spreadsheet layout
excel_preparations.py - Metadata Cache · Stores per-file inferred metadata, checksum, and column mapping
utils.py
Tool Routing
Retriever plus LLM-driven function selection
Operations
Domain functions, data processing, and output generation
- Functions · Controlled catalog for querying, aggregating, transforming, plotting, and editing spreadsheets
functions.py - Charts · Produces visual outputs from tabular results
functions.py - Workbook Writer · Rewrites edited spreadsheets for download
functions.py
Dependencies
LLM providers and external APIs
- Model Factory · Unifies OpenAI, hosted, and local model backends
llm_factory.py - OpenAI · Hosted model backend used for routing and reasoning
- Ollama · Local model backend for offline or self-hosted execution
- LLM Hub · Alternative hosted backend for chat or tool selection
- FX API · Converts currencies for financial normalization
Sample Data
Representative workbook inputs and notices
- Sample Data · Representative sales and material spreadsheets for demos and development
data
Connections 19
- Gradio UI → Loader: upload files · User uploads Excel files through the chat UI
- Gradio UI → Agent: chat prompt · Natural language requests enter the orchestration layer
- Gradio UI → File Map: download links · Restores edited workbook paths for UI download
- Loader → Prep: normalize sheet · Loaded workbooks are inspected for real headers and structure
- Prep → Metadata Cache: infer metadata · Extracted file meaning and mappings are cached locally
- Metadata Cache → Agent: file context · Cached metadata helps the agent target the right workbook
- Agent → Retriever: top candidates · Ranks the most relevant functions for the request
- Retriever → Functions: catalog search · Searches the function library by name and description
- Agent → Prompt: build prompt · Adds selection policy and parameter guidance
- Agent → Model Factory: select model · Resolves the configured model backend
- Model Factory → OpenAI: provider · Routes calls to OpenAI when configured
- Model Factory → Ollama: provider · Routes calls to a local Ollama server when configured
- Model Factory → LLM Hub: provider · Routes calls to a hosted llmhub model when configured
- Agent → Functions: execute tool · Runs the selected predefined function on spreadsheet data
- Functions → Charts: render chart · Some operations emit plots as final output
- Functions → Workbook Writer: write workbook · Edits are persisted into a new Excel file when needed
- Functions → FX API: convert values · Financial normalization may call an external FX service
- Functions → File Map: register output · Edited workbook paths are stored for later download
- Loader → Sample Data: read examples · Sample workbooks provide realistic development inputs