Spaces:
Sleeping
A newer version of the Gradio SDK is available: 6.26.0
title: RAG Python System
emoji: π€
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 4.44.1
app_file: app.py
pinned: false
license: mit
RAG Python System π€
A local-first Retrieval-Augmented Generation (RAG) system that enables intelligent question-answering over your documents using Hugging Face Inference API, ChromaDB, and Gradio.
Features
- π Document Processing: Converts PDF, DOCX, and TXT files to searchable format
- π Semantic Search: Uses sentence transformers for accurate context retrieval
- π€ AI-Powered Answers: Leverages Llama 3.2 3B via Hugging Face Inference API
- π¬ Interactive UI: Clean Gradio interface for easy interaction
- π― Source Citations: Provides references to source documents
How It Works
- Document Ingestion: Upload or use pre-loaded documents (currently includes "Think Python" guide)
- Semantic Chunking: Documents are split into meaningful chunks
- Vector Embeddings: Text chunks are converted to embeddings using
all-MiniLM-L6-v2 - Context Retrieval: Relevant chunks are retrieved based on your question
- Answer Generation: Llama 3.2 generates answers using the retrieved context
Setup Instructions
For Hugging Face Spaces Deployment
Fork or Duplicate this Space
- Click the three dots menu β "Duplicate Space"
Get Your Hugging Face Token
- Go to https://huggingface.co/settings/tokens
- Create a new token with
readpermissions - Copy the token (starts with
hf_)
Add Token to Space Secrets
- Go to your Space Settings
- Navigate to "Repository secrets"
- Add a new secret:
- Name:
HF_TOKEN - Value: Your token from step 2
- Name:
- Click "Add"
Restart the Space
- The Space will automatically rebuild and start
For Local Development
Clone the Repository
git clone https://github.com/monsara/rag-python-rag.git cd rag-python-ragCreate Virtual Environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activateInstall Dependencies
pip install -r requirements.txtSet Environment Variable
export HF_TOKEN=hf_your_token_hereRun the Application
python app.pyAccess the Interface
- Open your browser to
http://localhost:7860
- Open your browser to
Usage Examples
Try asking questions like:
- "How do if-else statements work in Python?"
- "What are the different types of loops in Python?"
- "How do you handle errors in Python?"
- "Explain Python functions with examples"
- "What is object-oriented programming in Python?"
Architecture
User Query β Gradio UI β Vector Store (ChromaDB) β Context Retrieval
β
HF Inference API
β
Llama 3.2 3B
β
Formatted Response
Tech Stack
- Frontend: Gradio 4.44.1
- LLM: Llama 3.2 3B Instruct (via Hugging Face Inference API)
- Embeddings: all-MiniLM-L6-v2 (Sentence Transformers)
- Vector DB: ChromaDB
- Document Processing: PyMuPDF, python-docx
- Text Splitting: LangChain Text Splitters
Rate Limits
Free Tier (Hugging Face Inference API):
- ~1000 requests/hour
- 1024 max tokens per response
- Shared infrastructure
For Production: Consider upgrading to Hugging Face Pro ($9/month) for:
- Higher rate limits
- Faster inference
- Priority support
Limitations
- Currently uses a single pre-loaded document ("Think Python")
- Free tier has rate limits
- Response quality depends on context relevance
- Max 1024 tokens per response
Roadmap
- File upload functionality
- Multiple document support
- Conversation history
- Custom model selection
- Advanced filtering options
- Export conversation feature
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details
Links
- GitHub Repository: monsara/rag-python-rag
- Documentation: See README.md for detailed technical documentation
- Hugging Face: Get your API token
Support
If you encounter issues:
- Check that
HF_TOKENis set correctly in Space secrets - Verify your token has
readpermissions - Check the Space logs for error messages
- Open an issue on GitHub
Built with β€οΈ using Hugging Face, Gradio, and ChromaDB