Kunal commited on
Commit ·
9d5c81b
1
Parent(s): 5de36cd
added Readme
Browse files
README.md
CHANGED
|
@@ -1,12 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
| 1 |
+
# 📄 Chat with PDF – Gemini AI Agent
|
| 2 |
+
|
| 3 |
+
A conversational AI agent that lets you upload any PDF and chat with its contents!
|
| 4 |
+
Built with [smolagents](https://github.com/smol-ai/smol-agents), [Google Gemini](https://aistudio.google.com/), [pypdf](https://pypdf.readthedocs.io/), and [Gradio](https://gradio.app/).
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
## 🌐 Try it Online
|
| 9 |
+
|
| 10 |
+
> **Live Demo:**
|
| 11 |
+
> [https://huggingface.co/spaces/your-username/your-space-name](https://huggingface.co/spaces/your-username/your-space-name)
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
## 🏗️ Tech Stack
|
| 16 |
+
|
| 17 |
+
| Layer | Technology | Purpose |
|
| 18 |
+
|--------------------|-------------------------------------------|--------------------------------------------|
|
| 19 |
+
| LLM Orchestration | [smolagents](https://github.com/smol-ai/smol-agents) | Agent framework, tool integration |
|
| 20 |
+
| Language Model | [Google Gemini 1.5 Flash](https://aistudio.google.com/) | Large Language Model for Q&A |
|
| 21 |
+
| LLM API Adapter | [LiteLLM](https://github.com/BerriAI/litellm) | Unified LLM API interface |
|
| 22 |
+
| PDF Processing | [pypdf](https://pypdf.readthedocs.io/) | Extracts text from uploaded PDF files |
|
| 23 |
+
| Web UI | [Gradio](https://gradio.app/) | Interactive chat interface |
|
| 24 |
+
| Environment Mgmt | [python-dotenv](https://pypi.org/project/python-dotenv/) | Loads environment variables (local dev) |
|
| 25 |
+
| Deployment | [Hugging Face Spaces](https://huggingface.co/spaces) | Cloud hosting (public demo) |
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## 🚀 Features
|
| 30 |
+
|
| 31 |
+
- **Upload any PDF** and extract its text instantly.
|
| 32 |
+
- **Ask questions** about the document—get answers powered by Google Gemini (1.5 Flash).
|
| 33 |
+
- **Conversational interface** using Gradio.
|
| 34 |
+
- **Runs locally or on Hugging Face Spaces**.
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## 🛠️ Installation (Local)
|
| 39 |
+
|
| 40 |
+
1. **Clone this repository:**
|
| 41 |
+
```bash
|
| 42 |
+
git clone https://github.com/yourusername/pdf-chat-gemini
|
| 43 |
+
cd pdf-chat-gemini
|
| 44 |
+
```
|
| 45 |
+
2. **Install dependencies:**
|
| 46 |
+
```bash
|
| 47 |
+
pip install -r requirements.txt
|
| 48 |
+
```
|
| 49 |
+
3. **Set up your Gemini API Key:**
|
| 50 |
+
- Get your key from [Google AI Studio](https://aistudio.google.com/app/apikey).
|
| 51 |
+
- Create a `.env` file in the project root:
|
| 52 |
+
```
|
| 53 |
+
GEMINI_API_KEY=your_actual_key_here
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
## 📝 Usage
|
| 58 |
+
|
| 59 |
+
### **Local**
|
| 60 |
+
```py
|
| 61 |
+
python app.py
|
| 62 |
+
```
|
| 63 |
+
Open [http://localhost:7860](http://localhost:7860) in your browser.
|
| 64 |
+
|
| 65 |
+
### **Hugging Face Spaces**
|
| 66 |
+
|
| 67 |
+
- Go to your Space: [https://huggingface.co/spaces/your-username/your-space-name](https://huggingface.co/spaces/your-username/your-space-name)
|
| 68 |
+
- Click **"Duplicate Space"** to make your own copy, or use it directly if public.
|
| 69 |
+
- Add your `GEMINI_API_KEY` as a secret in the Space settings (if you duplicate or deploy privately).
|
| 70 |
+
|
| 71 |
+
|
| 72 |
---
|
| 73 |
+
|
| 74 |
+
## ⚙️ Configuration
|
| 75 |
+
|
| 76 |
+
- **Model:** Uses `"gemini/gemini-1.5-flash"` by default. If you have access to `"gemini/gemini-1.5-pro"`, change the `model_id` in `app.py`.
|
| 77 |
+
- **API Key:** Must be a [Google AI Studio](https://aistudio.google.com/app/apikey) key, not a Vertex AI or GCP key.
|
| 78 |
+
- **No `api_base` needed** for Gemini AI Studio keys.
|
| 79 |
+
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## 🧩 How it Works
|
| 83 |
+
|
| 84 |
+
1. **Upload a PDF**: The app extracts all text using `pypdf`.
|
| 85 |
+
2. **Ask a question**: Your question and the extracted text are sent to the Gemini model via smolagents.
|
| 86 |
+
3. **Get answers**: The agent uses Gemini to answer your question, referencing the PDF content.
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## 🧑💻 For Developers
|
| 91 |
+
|
| 92 |
+
- **Add more tools**: Use the `@tool` decorator from smolagents to add custom functions.
|
| 93 |
+
- **Customize the UI**: Edit the Gradio blocks in `app.py`.
|
| 94 |
+
- **Chunking or RAG**: For large PDFs, consider splitting text into chunks and using retrieval-augmented generation.
|
| 95 |
+
|
| 96 |
+
---
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
## 📜 License
|
| 100 |
+
|
| 101 |
+
MIT License.
|
| 102 |
+
See [LICENSE](LICENSE) for details.
|
| 103 |
+
|
| 104 |
+
---
|
| 105 |
+
|
| 106 |
+
## 🙌 Acknowledgments
|
| 107 |
+
|
| 108 |
+
- [smol-ai/smol-agents](https://github.com/smol-ai/smol-agents)
|
| 109 |
+
- [Google AI Studio](https://aistudio.google.com/)
|
| 110 |
+
- [Gradio](https://gradio.app/)
|
| 111 |
+
- [pypdf](https://pypdf.readthedocs.io/)
|
| 112 |
+
|
| 113 |
+
---
|
| 114 |
+
|
| 115 |
+
**Enjoy chatting with your PDFs!**
|
| 116 |
+
For questions or contributions, open an issue or pull request.
|
| 117 |
+
|
| 118 |
---
|
| 119 |
|
| 120 |
+
|