A powerful chatbot that allows you to upload PDF documents and ask questions about their content using AI. Built with Streamlit, LangChain, and Groq LLM.
- 📄 Upload and process multiple PDF files
- 🤖 AI-powered question answering using Groq's LLM
- 🔍 Semantic search with FAISS vector database
- 💬 Interactive chat interface
- 📚 View source documents and page references
- ⚡ Fast response times with LLaMA 3.1 model
- Installation
- Getting API Keys
- Configuration
- Running Locally
- Deploying to Streamlit Cloud
- Usage
- Common Errors & FAQs
- Project Structure
- Technologies Used
git clone https://github.com/yourusername/pdf-chatbot-rag.git
cd pdf-chatbot-ragOn Windows:
python -m venv venv
venv\Scripts\activateOn macOS/Linux:
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtGroq provides fast LLM inference with their optimized infrastructure.
-
Visit Groq Console
- Go to: https://console.groq.com
-
Sign Up / Login
- Click "Sign Up" if you're new
- Use Google/GitHub for quick signup
- Or create account with email
-
Navigate to API Keys
- After login, go to the left sidebar
- Click on "API Keys"
-
Create New API Key
- Click "Create API Key" button
- Give it a name (e.g., "PDF Chatbot")
- Click "Submit"
-
Copy Your API Key
- IMPORTANT: Copy the key immediately
- You won't be able to see it again!
- It looks like:
gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
-
Save It Securely
- Store it in a password manager
- Never share it publicly
- Don't commit it to GitHub
We've provided a sample.env file. Follow these steps:
-
Locate the
sample.envfile in the project root -
Copy and rename it to
.env:On Windows (Command Prompt):
copy sample.env .envOn macOS/Linux (Terminal):
cp sample.env .env
Or manually:
- Right-click
sample.env - Select "Copy"
- Paste and rename to
.env
- Right-click
Open the .env file in any text editor and replace the placeholder:
Before:
GROQ_API_KEY=your_groq_api_key_hereAfter:
GROQ_API_KEY=gsk_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t- No spaces around the
=sign - No quotes needed
- Keep the
.envfile in the project root directory
Make sure your .env file won't be committed to Git:
Check if .gitignore contains:
.env
venv/
__pycache__/
*.pyc
Make sure your virtual environment is activated (see Installation Step 2)
streamlit run main2.pyOr if you named your file differently:
streamlit run your_filename.pyThe app will automatically open in your default browser at:
http://localhost:8501
If it doesn't open automatically, manually go to the URL shown in the terminal.
- GitHub account
- Your code pushed to a GitHub repository
git add .
git commit -m "Initial commit"
git push origin main.env is in .gitignore - Never push API keys to GitHub!
- Visit: https://streamlit.io/cloud
- Click "Sign up" or "Sign in with GitHub"
- Authorize Streamlit to access your GitHub
- Click "New app" button
- Fill in the deployment settings:
- Repository: Select your GitHub repo
- Branch:
main(or your default branch) - Main file path:
main2.py
This is crucial - you need to add your API key securely:
- Click on "Advanced settings"
- In the "Secrets" section, add:
GROQ_API_KEY = "gsk_your_actual_groq_api_key_here"- Use TOML format (with quotes)
- Must match the variable name in your
.envfile
- Click "Deploy!"
- Wait for the app to build (usually 2-5 minutes)
- Your app will be live at:
https://your-app-name.streamlit.app
Copy the URL and share it with anyone! They can use the app without needing API keys.
- Click "Browse files" in the sidebar
- Select one or multiple PDF files
- Click "Process Documents"
- Wait for processing to complete
- Type your question in the chat input at the bottom
- Press Enter or click Send
- The AI will answer based on your documents
- Click "View document sources" below any answer
- See which pages and documents were used
- Verify the accuracy of responses
- "What is this document about?"
- "Summarize the main points"
- "What are the key findings in section 3?"
- "Who are the authors mentioned?"
- "What is the conclusion?"
Problem: Missing dependencies
Solution:
pip install -r requirements.txt --upgradeProblem: API key not configured properly
Solution:
- Check if
.envfile exists in the project root - Verify the key is spelled correctly:
GROQ_API_KEY - No spaces around
=sign - Restart the Streamlit app after adding the key
Problem: Too many requests to Groq API
Solution:
- Wait a few minutes before trying again
- Groq has generous free tier limits
- Check your usage at: https://console.groq.com
Problem: PDF processing issue
Solution:
- Ensure PDFs are not password-protected
- Check if PDFs contain actual text (not just images)
- Try with a smaller PDF first
- Check file size - very large PDFs may timeout
Answer: Yes! Edit line 91 in main2.py:
model_name="llama-3.1-8b-instant" # Current modelAvailable Groq models:
llama-3.1-8b-instant(fastest)llama-3.1-70b-versatile(more capable)mixtral-8x7b-32768(good balance)gemma-7b-it(Google's model)
Answer:
- Groq offers a generous free tier
- No credit card required to start
- Check current limits at: https://console.groq.com/docs/rate-limits
Answer: Yes!
- Select multiple files when uploading
- They'll all be processed into one searchable database
- Ask questions across all documents
Answer:
- Chat history is stored in session state
- It clears when you refresh the page
- Use the "Clear Chat History" button to reset intentionally
Answer: Yes!
- Streamlit Cloud has a free tier
- Groq API has a free tier
- Perfect for personal projects and demos
Local:
# Save your changes
# Restart Streamlit
streamlit run main2.pyStreamlit Cloud:
- Just push to GitHub
- Streamlit automatically redeploys
- No manual action needed!
Answer:
- Text is extracted automatically
- Tables might not format perfectly
- Image-only PDFs won't work (text needed)
- For scanned PDFs, use OCR preprocessing
pdf-chatbot-rag/
│
├── main2.py # Main application file
├── requirements.txt # Python dependencies
├── sample.env # Sample environment file
├── .env # Your actual API keys (not in Git)
├── .gitignore # Files to ignore in Git
├── README.md # This file
│
└── .streamlit/ # Streamlit configuration (optional)
└── config.toml # Theme and settings
| Technology | Purpose |
|---|---|
| Streamlit | Web interface and deployment |
| LangChain | LLM orchestration framework |
| Groq | Fast LLM inference (LLaMA 3.1) |
| FAISS | Vector database for semantic search |
| HuggingFace | Sentence embeddings |
| PyPDF | PDF text extraction |
streamlit
langchain>=0.1.0
langchain-groq
langchain-community
langchain-text-splitters
langchain-core
langchain-huggingface
faiss-cpu
pypdf
sentence-transformers
python-dotenvContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues:
- Check the Common Errors & FAQs section
- Open an issue on GitHub
- Contact: your.email@example.com
- Groq for providing fast LLM inference
- LangChain for the excellent framework
- Streamlit for making deployment easy
- HuggingFace for embeddings models
If you find this useful, please give it a star on GitHub!
Made with ❤️ by RAJNI GANGWAR
Last Updated: November 2025