Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available:
5.49.1
π RAG Pedagogical Demo
A pedagogical web application demonstrating Retrieval Augmented Generation (RAG) systems for students and learners.
π Features
- Bilingual Interface (English/French)
- Document Processing: Upload PDF documents or use default corpus
- Configurable Retrieval:
- Choose embedding models
- Adjust chunk size and overlap
- Set top-k and similarity thresholds
- Configurable Generation:
- Select different LLMs
- Adjust temperature and max tokens
- Educational Visualization:
- View retrieved chunks with similarity scores
- See the exact prompt sent to the LLM
- Understand each step of the RAG pipeline
π Quick Start
Local Installation
# Clone the repository
git clone <your-repo-url>
cd RAG_pedago
# Install dependencies
pip install -r requirements.txt
# Run the application
python app.py
HuggingFace Spaces
This application is designed to run on HuggingFace Spaces with ZeroGPU support.
- Create a new Space on HuggingFace
- Select "Gradio" as the SDK
- Enable ZeroGPU in Space settings
- Upload all files from this repository
- The app will automatically deploy
π Usage
1. Corpus Management
- Upload your own PDF document or use the included default corpus about RAG
- Configure chunk size (100-1000 characters) and overlap (0-200 characters)
- Process the corpus to create embeddings
2. Retrieval Configuration
- Choose an embedding model:
all-MiniLM-L6-v2: Fast, lightweightall-mpnet-base-v2: Better quality, slowerparaphrase-multilingual-MiniLM-L12-v2: Multilingual support
- Set top-k (1-10): Number of chunks to retrieve
- Set similarity threshold (0.0-1.0): Minimum similarity score
3. Generation Configuration
- Select a language model:
zephyr-7b-beta: Fast, good qualityMistral-7B-Instruct-v0.2: High qualityLlama-2-7b-chat-hf: Alternative option
- Adjust temperature (0.0-2.0): Controls creativity
- Set max tokens (50-1000): Response length
4. Query & Results
- Enter your question
- Use example questions to get started
- View the generated answer
- Examine retrieved chunks with similarity scores
- Inspect the prompt sent to the LLM
ποΈ Architecture
βββββββββββββββββββ
β PDF Document β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Text Chunking β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Embeddings ββββββ Embedding Model
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β FAISS Index β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β User Query β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Retrieval ββββΊ Top-K Chunks
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Generation ββββββ Language Model
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Answer β
βββββββββββββββββββ
π οΈ Technical Stack
- Framework: Gradio 4.44.0
- Embeddings: Sentence Transformers
- Vector Store: FAISS
- LLMs: HuggingFace Inference API
- GPU: HuggingFace ZeroGPU
- PDF Processing: PyPDF2
π Files Structure
RAG_pedago/
βββ app.py # Main Gradio interface
βββ rag_system.py # Core RAG logic
βββ i18n.py # Internationalization
βββ requirements.txt # Python dependencies
βββ default_corpus.pdf # Default corpus about RAG
βββ default_corpus.txt # Source text for default corpus
βββ README.md # This file
π― Educational Goals
This application helps students understand:
- Document Processing: How text is split into chunks
- Embeddings: How text is converted to vectors
- Similarity Search: How relevant information is retrieved
- Prompt Engineering: How context is provided to LLMs
- Generation: How LLMs produce answers based on retrieved context
- Parameter Impact: How different settings affect results
π§ Configuration for HuggingFace Spaces
Create a README.md in your Space with this header:
---
title: RAG Pedagogical Demo
emoji: π
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit
---
π€ Contributing
Contributions are welcome! Feel free to:
- Add more embedding models
- Include additional LLMs
- Improve the interface
- Add more visualizations
- Enhance documentation
π License
MIT License - Feel free to use this for educational purposes.
π Acknowledgments
- HuggingFace for the Spaces platform and ZeroGPU
- Sentence Transformers for embeddings
- FAISS for efficient similarity search
- Gradio for the interface framework
π§ Contact
For questions or feedback, please open an issue on GitHub.