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