Spaces:
Sleeping
Sleeping
updated
Browse files
README.md
CHANGED
|
@@ -1,121 +1,130 @@
|
|
| 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 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
-
|
| 87 |
-
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
-
|
| 91 |
-
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
-
|
| 95 |
-
|
| 96 |
-
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
- **
|
| 103 |
-
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
pb59
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
title: AutoSQL
|
| 4 |
+
sdk: streamlit
|
| 5 |
+
emoji: π
|
| 6 |
+
colorTo: green
|
| 7 |
+
pinned: false
|
| 8 |
+
short_description: Talk2data
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Multi-Modal RAG System
|
| 12 |
+
|
| 13 |
+
## Overview data
|
| 14 |
+
This project is a modular, multi-modal Retrieval-Augmented Generation (RAG) system built with Streamlit. It enables natural language querying of business data, prompt tuning, PDF Q&A, and multi-agent reasoning. The system is designed for maintainability, local/cloud compatibility, and easy deployment (e.g., Hugging Face Spaces).
|
| 15 |
+
|
| 16 |
+
## Features
|
| 17 |
+
- **SQL Chat Agent:** Chat with an agent that generates and executes SQL queries on a SQLite business database.
|
| 18 |
+
- **Prompt Tuning Agent:** Improve user prompts for better SQL generation using LLM.
|
| 19 |
+
- **PDF Q&A Agent:** Upload PDFs and ask questions; the agent uses semantic search and LLM to answer.
|
| 20 |
+
- **Multi-Agent Q&A:** Complex queries are handled by a multi-agent system using SQL, prompt tuning, and PDF tools.
|
| 21 |
+
- **Session History:** All chat interactions are preserved and displayed.
|
| 22 |
+
- **Data Upload:** Upload CSV, Excel, or PDF files for querying and analysis.
|
| 23 |
+
- **Vector DB Integration:** Prompts and SQL pairs are stored in ChromaDB for semantic search and reuse.
|
| 24 |
+
- **Download/Save Results:** Download query results as CSV or save as database views.
|
| 25 |
+
|
| 26 |
+
## File Structure
|
| 27 |
+
- `app.py`: Main Streamlit app. All core logic, UI, and agent orchestration are here. Utility functions are defined locally for maintainability.
|
| 28 |
+
- `db_utils.py`: Database connection utilities (engine, SQLDatabase).
|
| 29 |
+
- `llm_utils.py`: LLM and prompt template setup.
|
| 30 |
+
- `chroma_utils.py`: ChromaDB client, collection, and embedding model setup.
|
| 31 |
+
- `pdf_utils.py`: PDF text extraction utility.
|
| 32 |
+
- `requirements.txt`: All required Python packages for local/cloud deployment.
|
| 33 |
+
- `business_data.db`: SQLite database file.
|
| 34 |
+
- `prompts.jsonl`: Stores prompt/SQL pairs for semantic search and history.
|
| 35 |
+
|
| 36 |
+
## How It Works
|
| 37 |
+
1. **Startup:**
|
| 38 |
+
- Launches Streamlit UI with custom styling.
|
| 39 |
+
- Initializes database, LLM, ChromaDB, and embedding model.
|
| 40 |
+
2. **Chat:**
|
| 41 |
+
- User enters a question.
|
| 42 |
+
- The agent checks for schema/meta queries, direct table requests, follow-ups, semantic matches, and generates SQL using LLM.
|
| 43 |
+
- Results are displayed and saved to history.
|
| 44 |
+
3. **Prompt Tuning:**
|
| 45 |
+
- User can improve prompts for better SQL generation.
|
| 46 |
+
4. **PDF Q&A:**
|
| 47 |
+
- Upload PDFs and ask questions; agent finds relevant context and answers using LLM.
|
| 48 |
+
5. **Multi-Agent Q&A:**
|
| 49 |
+
- Handles complex queries using all available tools.
|
| 50 |
+
6. **Data Upload:**
|
| 51 |
+
- Upload CSV/Excel/PDF files for analysis and querying.
|
| 52 |
+
7. **Vector DB:**
|
| 53 |
+
- Prompts and SQL pairs are stored in ChromaDB for semantic search and reuse.
|
| 54 |
+
|
| 55 |
+
## Setup & Usage
|
| 56 |
+
1. **Install Requirements:**
|
| 57 |
+
```bash
|
| 58 |
+
pip install -r requirements.txt
|
| 59 |
+
```
|
| 60 |
+
2. **Run the App:**
|
| 61 |
+
```bash
|
| 62 |
+
streamlit run app.py
|
| 63 |
+
```
|
| 64 |
+
3. **Upload Data:**
|
| 65 |
+
- Use the sidebar to upload CSV, Excel, or PDF files.
|
| 66 |
+
4. **Interact:**
|
| 67 |
+
- Use the chat input to ask questions about your data.
|
| 68 |
+
- Use tabs for prompt tuning, PDF Q&A, and multi-agent queries.
|
| 69 |
+
|
| 70 |
+
## Deployment
|
| 71 |
+
- Designed for local use and cloud platforms (e.g., Hugging Face Spaces).
|
| 72 |
+
- All file paths are relative for compatibility.
|
| 73 |
+
- Modular structure allows easy maintenance and extension.
|
| 74 |
+
|
| 75 |
+
## Customization
|
| 76 |
+
- To add new agents/tools, define them locally in `app.py` or as utility modules.
|
| 77 |
+
- To change the database, update `db_utils.py` and the database file.
|
| 78 |
+
- To extend prompt logic, modify the prompt templates in `llm_utils.py` or directly in `app.py`.
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
## Architecture
|
| 82 |
+
|
| 83 |
+
The Multi-Modal RAG System is designed with modularity and extensibility in mind. The architecture consists of the following layers and components:
|
| 84 |
+
|
| 85 |
+
- **Streamlit UI Layer:**
|
| 86 |
+
- Provides the chat interface, sidebar for file uploads, and tabbed navigation for different agent modes.
|
| 87 |
+
- Displays session history, query results, and agent responses.
|
| 88 |
+
|
| 89 |
+
- **Core Logic Layer (`app.py`):**
|
| 90 |
+
- Orchestrates all agent interactions, data flow, and UI updates.
|
| 91 |
+
- Contains local definitions for utility functions and agent logic for maintainability.
|
| 92 |
+
|
| 93 |
+
- **Utility Modules:**
|
| 94 |
+
- `db_utils.py`: Handles database engine and connection setup.
|
| 95 |
+
- `llm_utils.py`: Manages LLM initialization and prompt templates.
|
| 96 |
+
- `chroma_utils.py`: Sets up ChromaDB client, collections, and embedding models for semantic search.
|
| 97 |
+
- `pdf_utils.py`: Extracts text from uploaded PDF files.
|
| 98 |
+
|
| 99 |
+
- **Agents and Tools:**
|
| 100 |
+
- **SQL Chat Agent:** Generates and executes SQL queries using LLM and database schema.
|
| 101 |
+
- **Prompt Tuning Agent:** Improves user prompts for more accurate SQL generation.
|
| 102 |
+
- **PDF Q&A Agent:** Uses semantic search and LLM to answer questions about uploaded PDFs.
|
| 103 |
+
- **Multi-Agent Q&A:** Combines all tools for complex, context-aware reasoning.
|
| 104 |
+
|
| 105 |
+
- **Data Flow:**
|
| 106 |
+
1. User submits a query or uploads a file via the UI.
|
| 107 |
+
2. The appropriate agent/tool processes the input, using the database, LLM, or ChromaDB as needed.
|
| 108 |
+
3. Results are displayed in the UI and saved to session history.
|
| 109 |
+
4. Prompts and SQL pairs are stored in ChromaDB and `prompts.jsonl` for future semantic search and reuse.
|
| 110 |
+
|
| 111 |
+
- **Extensibility:**
|
| 112 |
+
- New agents/tools can be added as local functions or utility modules.
|
| 113 |
+
- The modular structure allows easy updates for deployment on cloud platforms or local environments.
|
| 114 |
+
|
| 115 |
+
**Diagram (Textual):**
|
| 116 |
+
|
| 117 |
+
```
|
| 118 |
+
User ββ> Streamlit UI ββ> app.py ββ> [db_utils | llm_utils | chroma_utils | pdf_utils]
|
| 119 |
+
β β
|
| 120 |
+
β ββ> Agents/Tools (SQL, Prompt, PDF, Multi-Agent)
|
| 121 |
+
β
|
| 122 |
+
ββ> Results, History, Downloads, Views
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
## License
|
| 127 |
+
MIT License
|
| 128 |
+
|
| 129 |
+
## Author
|
| 130 |
pb59
|