beerohan commited on
Commit
1969b37
Β·
1 Parent(s): 0a92a68

Update README files

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