joelg commited on
Commit
5fffa7e
Β·
1 Parent(s): 8a18ce0
Files changed (3) hide show
  1. README.md +41 -174
  2. README_old.md +193 -0
  3. SPACE_README.md +0 -60
README.md CHANGED
@@ -1,160 +1,3 @@
1
- # πŸŽ“ RAG Pedagogical Demo
2
-
3
- A pedagogical web application demonstrating Retrieval Augmented Generation (RAG) systems for students and learners.
4
-
5
- ## 🌟 Features
6
-
7
- - **Bilingual Interface** (English/French)
8
- - **Document Processing**: Upload PDF documents or use default corpus
9
- - **Configurable Retrieval**:
10
- - Choose embedding models
11
- - Adjust chunk size and overlap
12
- - Set top-k and similarity thresholds
13
- - **Configurable Generation**:
14
- - Select different LLMs
15
- - Adjust temperature and max tokens
16
- - **Educational Visualization**:
17
- - View retrieved chunks with similarity scores
18
- - See the exact prompt sent to the LLM
19
- - Understand each step of the RAG pipeline
20
-
21
- ## πŸš€ Quick Start
22
-
23
- ### Local Installation
24
-
25
- ```bash
26
- # Clone the repository
27
- git clone <your-repo-url>
28
- cd RAG_pedago
29
-
30
- # Install dependencies
31
- pip install -r requirements.txt
32
-
33
- # Run the application
34
- python app.py
35
- ```
36
-
37
- ### HuggingFace Spaces
38
-
39
- This application is designed to run on HuggingFace Spaces with ZeroGPU support.
40
-
41
- 1. Create a new Space on HuggingFace
42
- 2. Select "Gradio" as the SDK
43
- 3. Enable ZeroGPU in Space settings
44
- 4. Upload all files from this repository
45
- 5. The app will automatically deploy
46
-
47
- ## πŸ“š Usage
48
-
49
- ### 1. Corpus Management
50
- - Upload your own PDF document or use the included default corpus about RAG
51
- - Configure chunk size (100-1000 characters) and overlap (0-200 characters)
52
- - Process the corpus to create embeddings
53
-
54
- ### 2. Retrieval Configuration
55
- - Choose an embedding model:
56
- - `all-MiniLM-L6-v2`: Fast, lightweight
57
- - `all-mpnet-base-v2`: Better quality, slower
58
- - `paraphrase-multilingual-MiniLM-L12-v2`: Multilingual support
59
- - Set top-k (1-10): Number of chunks to retrieve
60
- - Set similarity threshold (0.0-1.0): Minimum similarity score
61
-
62
- ### 3. Generation Configuration
63
- - Select a language model:
64
- - `zephyr-7b-beta`: Fast, good quality
65
- - `Mistral-7B-Instruct-v0.2`: High quality
66
- - `Llama-2-7b-chat-hf`: Alternative option
67
- - Adjust temperature (0.0-2.0): Controls creativity
68
- - Set max tokens (50-1000): Response length
69
-
70
- ### 4. Query & Results
71
- - Enter your question
72
- - Use example questions to get started
73
- - View the generated answer
74
- - Examine retrieved chunks with similarity scores
75
- - Inspect the prompt sent to the LLM
76
-
77
- ## πŸ—οΈ Architecture
78
-
79
- ```
80
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
81
- β”‚ PDF Document β”‚
82
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
83
- β”‚
84
- β–Ό
85
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
86
- β”‚ Text Chunking β”‚
87
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
88
- β”‚
89
- β–Ό
90
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
91
- β”‚ Embeddings │◄──── Embedding Model
92
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
93
- β”‚
94
- β–Ό
95
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
96
- β”‚ FAISS Index β”‚
97
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
98
- β”‚
99
- β–Ό
100
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
101
- β”‚ User Query β”‚
102
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
103
- β”‚
104
- β–Ό
105
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
106
- β”‚ Retrieval │──► Top-K Chunks
107
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
108
- β”‚
109
- β–Ό
110
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
111
- β”‚ Generation │◄──── Language Model
112
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
113
- β”‚
114
- β–Ό
115
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
116
- β”‚ Answer β”‚
117
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
118
- ```
119
-
120
- ## πŸ› οΈ Technical Stack
121
-
122
- - **Framework**: Gradio 4.44.0
123
- - **Embeddings**: Sentence Transformers
124
- - **Vector Store**: FAISS
125
- - **LLMs**: HuggingFace Inference API
126
- - **GPU**: HuggingFace ZeroGPU
127
- - **PDF Processing**: PyPDF2
128
-
129
- ## πŸ“ Files Structure
130
-
131
- ```
132
- RAG_pedago/
133
- β”œβ”€β”€ app.py # Main Gradio interface
134
- β”œβ”€β”€ rag_system.py # Core RAG logic
135
- β”œβ”€β”€ i18n.py # Internationalization
136
- β”œβ”€β”€ requirements.txt # Python dependencies
137
- β”œβ”€β”€ default_corpus.pdf # Default corpus about RAG
138
- β”œβ”€β”€ default_corpus.txt # Source text for default corpus
139
- └── README.md # This file
140
- ```
141
-
142
- ## 🎯 Educational Goals
143
-
144
- This application helps students understand:
145
-
146
- 1. **Document Processing**: How text is split into chunks
147
- 2. **Embeddings**: How text is converted to vectors
148
- 3. **Similarity Search**: How relevant information is retrieved
149
- 4. **Prompt Engineering**: How context is provided to LLMs
150
- 5. **Generation**: How LLMs produce answers based on retrieved context
151
- 6. **Parameter Impact**: How different settings affect results
152
-
153
- ## πŸ”§ Configuration for HuggingFace Spaces
154
-
155
- Create a `README.md` in your Space with this header:
156
-
157
- ```yaml
158
  ---
159
  title: RAG Pedagogical Demo
160
  emoji: πŸŽ“
@@ -166,28 +9,52 @@ app_file: app.py
166
  pinned: false
167
  license: mit
168
  ---
169
- ```
170
 
171
- ## 🀝 Contributing
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
- Contributions are welcome! Feel free to:
174
- - Add more embedding models
175
- - Include additional LLMs
176
- - Improve the interface
177
- - Add more visualizations
178
- - Enhance documentation
179
 
180
- ## πŸ“„ License
 
 
 
181
 
182
- MIT License - Feel free to use this for educational purposes.
183
 
184
- ## πŸ™ Acknowledgments
 
 
 
 
185
 
186
- - HuggingFace for the Spaces platform and ZeroGPU
187
- - Sentence Transformers for embeddings
188
- - FAISS for efficient similarity search
189
- - Gradio for the interface framework
190
 
191
- ## πŸ“§ Contact
 
 
 
 
 
 
 
 
192
 
193
- For questions or feedback, please open an issue on GitHub.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: RAG Pedagogical Demo
3
  emoji: πŸŽ“
 
9
  pinned: false
10
  license: mit
11
  ---
 
12
 
13
+ # πŸŽ“ RAG Pedagogical Demo
14
+
15
+ An interactive educational application to learn about Retrieval Augmented Generation (RAG) systems.
16
+
17
+ ## What is RAG?
18
+
19
+ Retrieval Augmented Generation (RAG) combines information retrieval with language generation to create more accurate and grounded AI responses. Instead of relying solely on a language model's training data, RAG systems:
20
+
21
+ 1. **Retrieve** relevant information from a document corpus
22
+ 2. **Augment** the query with this retrieved context
23
+ 3. **Generate** an answer based on both the query and the retrieved information
24
+
25
+ ## Features
26
+
27
+ - πŸ“š **Upload your own PDFs** or use the default corpus
28
+ - πŸ”§ **Configure retrieval parameters**: embedding models, chunk size, top-k, similarity threshold
29
+ - πŸ€– **Configure generation parameters**: LLM selection, temperature, max tokens
30
+ - πŸ“Š **Visualize the process**: see retrieved chunks, similarity scores, and prompts
31
+ - 🌍 **Bilingual interface**: English and French
32
 
33
+ ## How to Use
 
 
 
 
 
34
 
35
+ 1. **Corpus Tab**: Upload a PDF or use the default corpus about RAG
36
+ 2. **Retrieval Tab**: Choose embedding model and retrieval parameters
37
+ 3. **Generation Tab**: Select language model and generation settings
38
+ 4. **Query Tab**: Ask questions and see how RAG works!
39
 
40
+ ## Educational Value
41
 
42
+ This demo helps you understand:
43
+ - How documents are processed and chunked
44
+ - How semantic search retrieves relevant information
45
+ - How context is provided to language models
46
+ - How different parameters affect the results
47
 
48
+ Perfect for students, educators, and anyone curious about modern AI systems!
 
 
 
49
 
50
+ ## Technology
51
+
52
+ - **Framework**: Gradio
53
+ - **Embeddings**: Sentence Transformers
54
+ - **Vector Store**: FAISS
55
+ - **LLMs**: HuggingFace Inference API
56
+ - **Infrastructure**: HuggingFace ZeroGPU
57
+
58
+ ---
59
 
60
+ *Note: This application runs on ZeroGPU. Initial requests may take longer as models are loaded.*
README_old.md ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # πŸŽ“ RAG Pedagogical Demo
2
+
3
+ A pedagogical web application demonstrating Retrieval Augmented Generation (RAG) systems for students and learners.
4
+
5
+ ## 🌟 Features
6
+
7
+ - **Bilingual Interface** (English/French)
8
+ - **Document Processing**: Upload PDF documents or use default corpus
9
+ - **Configurable Retrieval**:
10
+ - Choose embedding models
11
+ - Adjust chunk size and overlap
12
+ - Set top-k and similarity thresholds
13
+ - **Configurable Generation**:
14
+ - Select different LLMs
15
+ - Adjust temperature and max tokens
16
+ - **Educational Visualization**:
17
+ - View retrieved chunks with similarity scores
18
+ - See the exact prompt sent to the LLM
19
+ - Understand each step of the RAG pipeline
20
+
21
+ ## πŸš€ Quick Start
22
+
23
+ ### Local Installation
24
+
25
+ ```bash
26
+ # Clone the repository
27
+ git clone <your-repo-url>
28
+ cd RAG_pedago
29
+
30
+ # Install dependencies
31
+ pip install -r requirements.txt
32
+
33
+ # Run the application
34
+ python app.py
35
+ ```
36
+
37
+ ### HuggingFace Spaces
38
+
39
+ This application is designed to run on HuggingFace Spaces with ZeroGPU support.
40
+
41
+ 1. Create a new Space on HuggingFace
42
+ 2. Select "Gradio" as the SDK
43
+ 3. Enable ZeroGPU in Space settings
44
+ 4. Upload all files from this repository
45
+ 5. The app will automatically deploy
46
+
47
+ ## πŸ“š Usage
48
+
49
+ ### 1. Corpus Management
50
+ - Upload your own PDF document or use the included default corpus about RAG
51
+ - Configure chunk size (100-1000 characters) and overlap (0-200 characters)
52
+ - Process the corpus to create embeddings
53
+
54
+ ### 2. Retrieval Configuration
55
+ - Choose an embedding model:
56
+ - `all-MiniLM-L6-v2`: Fast, lightweight
57
+ - `all-mpnet-base-v2`: Better quality, slower
58
+ - `paraphrase-multilingual-MiniLM-L12-v2`: Multilingual support
59
+ - Set top-k (1-10): Number of chunks to retrieve
60
+ - Set similarity threshold (0.0-1.0): Minimum similarity score
61
+
62
+ ### 3. Generation Configuration
63
+ - Select a language model:
64
+ - `zephyr-7b-beta`: Fast, good quality
65
+ - `Mistral-7B-Instruct-v0.2`: High quality
66
+ - `Llama-2-7b-chat-hf`: Alternative option
67
+ - Adjust temperature (0.0-2.0): Controls creativity
68
+ - Set max tokens (50-1000): Response length
69
+
70
+ ### 4. Query & Results
71
+ - Enter your question
72
+ - Use example questions to get started
73
+ - View the generated answer
74
+ - Examine retrieved chunks with similarity scores
75
+ - Inspect the prompt sent to the LLM
76
+
77
+ ## πŸ—οΈ Architecture
78
+
79
+ ```
80
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
81
+ β”‚ PDF Document β”‚
82
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
83
+ β”‚
84
+ β–Ό
85
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
86
+ β”‚ Text Chunking β”‚
87
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
88
+ β”‚
89
+ β–Ό
90
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
91
+ β”‚ Embeddings │◄──── Embedding Model
92
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
93
+ β”‚
94
+ β–Ό
95
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
96
+ β”‚ FAISS Index β”‚
97
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
98
+ β”‚
99
+ β–Ό
100
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
101
+ β”‚ User Query β”‚
102
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
103
+ β”‚
104
+ β–Ό
105
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
106
+ β”‚ Retrieval │──► Top-K Chunks
107
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
108
+ β”‚
109
+ β–Ό
110
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
111
+ β”‚ Generation │◄──── Language Model
112
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
113
+ β”‚
114
+ β–Ό
115
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
116
+ β”‚ Answer β”‚
117
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
118
+ ```
119
+
120
+ ## πŸ› οΈ Technical Stack
121
+
122
+ - **Framework**: Gradio 4.44.0
123
+ - **Embeddings**: Sentence Transformers
124
+ - **Vector Store**: FAISS
125
+ - **LLMs**: HuggingFace Inference API
126
+ - **GPU**: HuggingFace ZeroGPU
127
+ - **PDF Processing**: PyPDF2
128
+
129
+ ## πŸ“ Files Structure
130
+
131
+ ```
132
+ RAG_pedago/
133
+ β”œβ”€β”€ app.py # Main Gradio interface
134
+ β”œβ”€β”€ rag_system.py # Core RAG logic
135
+ β”œβ”€β”€ i18n.py # Internationalization
136
+ β”œβ”€β”€ requirements.txt # Python dependencies
137
+ β”œβ”€β”€ default_corpus.pdf # Default corpus about RAG
138
+ β”œβ”€β”€ default_corpus.txt # Source text for default corpus
139
+ └── README.md # This file
140
+ ```
141
+
142
+ ## 🎯 Educational Goals
143
+
144
+ This application helps students understand:
145
+
146
+ 1. **Document Processing**: How text is split into chunks
147
+ 2. **Embeddings**: How text is converted to vectors
148
+ 3. **Similarity Search**: How relevant information is retrieved
149
+ 4. **Prompt Engineering**: How context is provided to LLMs
150
+ 5. **Generation**: How LLMs produce answers based on retrieved context
151
+ 6. **Parameter Impact**: How different settings affect results
152
+
153
+ ## πŸ”§ Configuration for HuggingFace Spaces
154
+
155
+ Create a `README.md` in your Space with this header:
156
+
157
+ ```yaml
158
+ ---
159
+ title: RAG Pedagogical Demo
160
+ emoji: πŸŽ“
161
+ colorFrom: blue
162
+ colorTo: purple
163
+ sdk: gradio
164
+ sdk_version: 4.44.0
165
+ app_file: app.py
166
+ pinned: false
167
+ license: mit
168
+ ---
169
+ ```
170
+
171
+ ## 🀝 Contributing
172
+
173
+ Contributions are welcome! Feel free to:
174
+ - Add more embedding models
175
+ - Include additional LLMs
176
+ - Improve the interface
177
+ - Add more visualizations
178
+ - Enhance documentation
179
+
180
+ ## πŸ“„ License
181
+
182
+ MIT License - Feel free to use this for educational purposes.
183
+
184
+ ## πŸ™ Acknowledgments
185
+
186
+ - HuggingFace for the Spaces platform and ZeroGPU
187
+ - Sentence Transformers for embeddings
188
+ - FAISS for efficient similarity search
189
+ - Gradio for the interface framework
190
+
191
+ ## πŸ“§ Contact
192
+
193
+ For questions or feedback, please open an issue on GitHub.
SPACE_README.md DELETED
@@ -1,60 +0,0 @@
1
- ---
2
- title: RAG Pedagogical Demo
3
- emoji: πŸŽ“
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 4.44.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- # πŸŽ“ RAG Pedagogical Demo
14
-
15
- An interactive educational application to learn about Retrieval Augmented Generation (RAG) systems.
16
-
17
- ## What is RAG?
18
-
19
- Retrieval Augmented Generation (RAG) combines information retrieval with language generation to create more accurate and grounded AI responses. Instead of relying solely on a language model's training data, RAG systems:
20
-
21
- 1. **Retrieve** relevant information from a document corpus
22
- 2. **Augment** the query with this retrieved context
23
- 3. **Generate** an answer based on both the query and the retrieved information
24
-
25
- ## Features
26
-
27
- - πŸ“š **Upload your own PDFs** or use the default corpus
28
- - πŸ”§ **Configure retrieval parameters**: embedding models, chunk size, top-k, similarity threshold
29
- - πŸ€– **Configure generation parameters**: LLM selection, temperature, max tokens
30
- - πŸ“Š **Visualize the process**: see retrieved chunks, similarity scores, and prompts
31
- - 🌍 **Bilingual interface**: English and French
32
-
33
- ## How to Use
34
-
35
- 1. **Corpus Tab**: Upload a PDF or use the default corpus about RAG
36
- 2. **Retrieval Tab**: Choose embedding model and retrieval parameters
37
- 3. **Generation Tab**: Select language model and generation settings
38
- 4. **Query Tab**: Ask questions and see how RAG works!
39
-
40
- ## Educational Value
41
-
42
- This demo helps you understand:
43
- - How documents are processed and chunked
44
- - How semantic search retrieves relevant information
45
- - How context is provided to language models
46
- - How different parameters affect the results
47
-
48
- Perfect for students, educators, and anyone curious about modern AI systems!
49
-
50
- ## Technology
51
-
52
- - **Framework**: Gradio
53
- - **Embeddings**: Sentence Transformers
54
- - **Vector Store**: FAISS
55
- - **LLMs**: HuggingFace Inference API
56
- - **Infrastructure**: HuggingFace ZeroGPU
57
-
58
- ---
59
-
60
- *Note: This application runs on ZeroGPU. Initial requests may take longer as models are loaded.*