berohan commited on
Commit
98857c4
Β·
verified Β·
1 Parent(s): 1eb5e61

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +243 -0
README.md ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Studyson
3
+ emoji: πŸ“š
4
+ colorFrom: purple
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ # Studyson - RAG Document QA & Summarization API
11
+
12
+ A full-stack Retrieval-Augmented Generation (RAG) system for intelligent document question-answering and summarization. Built with FastAPI, LlamaIndex, and Groq AI.
13
+
14
+ ## Features
15
+
16
+ - **πŸ“„ PDF Document Processing**: Upload and index PDF documents with intelligent text extraction
17
+ - **🌐 Web Content Scraping**: Scrape and index content from URLs
18
+ - **πŸ’¬ Interactive Q&A Chat**: Ask questions about your documents with streaming responses
19
+ - **πŸ“ Smart Summarization**: Generate concise summaries of indexed documents
20
+ - **πŸ” Source Citations**: Get verifiable citations with exact source snippets
21
+ - **⚑ Real-time Streaming**: Token-by-token streaming for responsive user experience
22
+ - **🎨 Modern UI**: Clean, responsive web interface with tabbed navigation
23
+ - **🐳 Docker Support**: Easy deployment with Docker and Docker Compose
24
+
25
+ ## Tech Stack
26
+
27
+ ### Backend
28
+ - **FastAPI**: Modern Python web framework
29
+ - **LlamaIndex**: RAG orchestration and document indexing
30
+ - **Groq**: Lightning-fast LLM inference (Llama 3.1)
31
+ - **FastEmbed**: Lightweight embeddings (BGE-small)
32
+ - **PyMuPDF**: Advanced PDF text extraction
33
+ - **BeautifulSoup**: HTML parsing and web scraping
34
+ - **Pydantic**: Data validation and settings management
35
+
36
+ ### Frontend
37
+ - **HTML5/CSS3/JavaScript**: Vanilla web technologies
38
+ - **Server-Sent Events (SSE)**: Real-time streaming responses
39
+
40
+ ## Architecture
41
+
42
+ ### Ingestion Pipeline
43
+ 1. User uploads PDF or provides URL
44
+ 2. Content extraction (PyMuPDF for PDFs, BeautifulSoup for web)
45
+ 3. Text chunking and embedding via LlamaIndex + FastEmbed
46
+ 4. In-memory vector index creation
47
+
48
+ ### Query Pipeline
49
+ 1. Question embedding generation
50
+ 2. Semantic similarity search for relevant chunks
51
+ 3. Context + question sent to Groq LLM
52
+ 4. Streaming response with source citations
53
+
54
+ ## Installation
55
+
56
+ ### Prerequisites
57
+ - Python 3.10 or higher
58
+ - Groq API key ([Get it free here](https://console.groq.com))
59
+
60
+ ### Local Setup
61
+
62
+ 1. **Clone the repository**
63
+ ```bash
64
+ git clone <repository-url>
65
+ cd studyrag
66
+ ```
67
+
68
+ 2. **Create virtual environment**
69
+ ```bash
70
+ python -m venv venv
71
+ source venv/bin/activate # On Windows: venv\Scripts\activate
72
+ ```
73
+
74
+ 3. **Install dependencies**
75
+ ```bash
76
+ pip install -r requirements.txt
77
+ ```
78
+
79
+ 4. **Set up environment variables**
80
+ ```bash
81
+ cp .env.example .env
82
+ ```
83
+
84
+ Edit `.env` and add your Groq API key:
85
+ ```
86
+ GROQ_API_KEY=your_groq_api_key_here
87
+ PORT=7860
88
+ HOST=0.0.0.0
89
+ ```
90
+
91
+ 5. **Run the application**
92
+ ```bash
93
+ uvicorn app.main:app --reload --port 7860
94
+ ```
95
+
96
+ 6. **Access the application**
97
+
98
+ Open your browser and navigate to: `http://localhost:7860`
99
+
100
+ ### Docker Setup
101
+
102
+ 1. **Set environment variables**
103
+ ```bash
104
+ cp .env.example .env
105
+ # Edit .env with your Groq API key
106
+ ```
107
+
108
+ 2. **Build and run with Docker Compose**
109
+ ```bash
110
+ docker-compose up --build
111
+ ```
112
+
113
+ ## API Endpoints
114
+
115
+ | Method | Endpoint | Description |
116
+ |--------|----------|-------------|
117
+ | GET | `/` | Serves the web UI |
118
+ | POST | `/upload` | Upload PDF document |
119
+ | POST | `/scrape` | Scrape URL content |
120
+ | POST | `/stream_query` | Stream Q&A response |
121
+ | POST | `/query` | Get Q&A response |
122
+ | POST | `/summarize` | Generate summary |
123
+ | POST | `/reset` | Clear all documents |
124
+ | GET | `/status` | Get system status |
125
+
126
+ ## Project Structure
127
+
128
+ ```
129
+ studyrag/
130
+ β”œβ”€β”€ app/
131
+ β”‚ β”œβ”€β”€ __init__.py
132
+ β”‚ β”œβ”€β”€ main.py # FastAPI application
133
+ β”‚ β”œβ”€β”€ config.py # Configuration settings
134
+ β”‚ β”œβ”€β”€ models/
135
+ β”‚ β”‚ └── schemas.py # Pydantic models
136
+ β”‚ β”œβ”€β”€ services/
137
+ β”‚ β”‚ └── rag_service.py # RAG logic
138
+ β”‚ └── utils/
139
+ β”‚ └── document_processor.py
140
+ β”œβ”€β”€ static/
141
+ β”‚ β”œβ”€β”€ css/style.css
142
+ β”‚ β”œβ”€β”€ js/app.js
143
+ β”‚ └── index.html
144
+ β”œβ”€β”€ .env.example
145
+ β”œβ”€β”€ .gitignore
146
+ β”œβ”€β”€ Dockerfile
147
+ β”œβ”€β”€ docker-compose.yml
148
+ β”œβ”€β”€ Procfile
149
+ β”œβ”€β”€ requirements.txt
150
+ └── README.md
151
+ ```
152
+
153
+ ## Configuration
154
+
155
+ ### Environment Variables
156
+
157
+ - `GROQ_API_KEY`: Your Groq API key (required, free tier available)
158
+ - `HOST`: Server host (default: 0.0.0.0)
159
+ - `PORT`: Server port (default: 7860)
160
+
161
+ ### Application Settings
162
+
163
+ Edit `app/config.py` to modify:
164
+ - `upload_dir`: Upload directory path
165
+ - `max_file_size`: Maximum file size (default: 10MB)
166
+
167
+ ## Deployment
168
+
169
+ ### Deploy to Hugging Face Spaces (Recommended - Free)
170
+
171
+ 1. Push code to GitHub
172
+ 2. Go to [huggingface.co](https://huggingface.co) and create an account
173
+ 3. Click your profile β†’ **New Space**
174
+ 4. Configure:
175
+ - **Space name**: `studyson`
176
+ - **SDK**: Select **Docker**
177
+ - **Hardware**: CPU basic (free)
178
+ 5. Under **Files** β†’ Link to GitHub repo (or upload files)
179
+ 6. Add secret: `GROQ_API_KEY` in Space Settings β†’ Variables
180
+ 7. The Space will auto-build and deploy!
181
+
182
+ **Your app will be live at:** `https://huggingface.co/spaces/YOUR_USERNAME/studyson`
183
+
184
+ ## Features in Detail
185
+
186
+ ### RAG Pipeline
187
+ - **Chunking**: Intelligent text splitting for optimal context windows
188
+ - **Embeddings**: FastEmbed BGE-small for semantic understanding (lightweight)
189
+ - **Retrieval**: Top-k similarity search with configurable parameters
190
+ - **Generation**: Groq Llama 3.1 for fast, accurate responses
191
+
192
+ ### Streaming
193
+ - Server-Sent Events (SSE) for real-time token delivery
194
+ - Progressive rendering in the UI
195
+ - Graceful error handling
196
+
197
+ ### Source Attribution
198
+ - Exact text snippets from source documents
199
+ - Similarity scores for transparency
200
+ - Multiple source support per answer
201
+
202
+ ## Limitations
203
+
204
+ - In-memory vector storage (resets on restart)
205
+ - PDF-only document support (extensible to other formats)
206
+ - Single-user session management
207
+ - No authentication/authorization
208
+
209
+ ## Troubleshooting
210
+
211
+ ### Common Issues
212
+
213
+ **Import errors:**
214
+ ```bash
215
+ pip install --upgrade -r requirements.txt
216
+ ```
217
+
218
+ **API key errors:**
219
+ - Verify your `.env` file has the correct `GROQ_API_KEY`
220
+ - Check API key validity at [console.groq.com](https://console.groq.com)
221
+
222
+ **Port already in use:**
223
+ ```bash
224
+ uvicorn app.main:app --port 8000
225
+ ```
226
+
227
+ **File upload fails:**
228
+ - Check file size is under 10MB
229
+
230
+ ## License
231
+
232
+ MIT License - feel free to use this project for learning and development.
233
+
234
+ ## Acknowledgments
235
+
236
+ - [LlamaIndex](https://www.llamaindex.ai/) for RAG orchestration
237
+ - [Groq](https://groq.com/) for lightning-fast LLM inference
238
+ - [FastEmbed](https://github.com/qdrant/fastembed) for lightweight embeddings
239
+ - [FastAPI](https://fastapi.tiangolo.com/) for the web framework
240
+
241
+ ---
242
+
243
+ Built with ❀️ using RAG technology