Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,310 +1,319 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
#
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
#
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
```
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
```
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
βββ
|
| 125 |
-
βββ
|
| 126 |
-
βββ
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
#
|
| 131 |
-
|
| 132 |
-
#
|
| 133 |
-
|
| 134 |
-
#
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
##
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
#
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
-
|
| 179 |
-
|
| 180 |
-
##
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
#
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
#
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
#
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
#
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
#
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
βββ
|
| 268 |
-
βββ
|
| 269 |
-
βββ
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
#
|
| 274 |
-
|
| 275 |
-
#
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
##
|
| 285 |
-
|
| 286 |
-
- **
|
| 287 |
-
- **
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
-
|
| 310 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: FastAPI + Streamlit Demo
|
| 3 |
+
emoji: π³
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_file: Dockerfile
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
# RAG Personal Diary Chatbot
|
| 11 |
+
|
| 12 |
+
## π Project Description
|
| 13 |
+
|
| 14 |
+
RAG Personal Diary Chatbot is an intelligent chatbot application that uses RAG (Retrieval-Augmented Generation) architecture to interact with users' personal diaries. The application allows users to ask questions about diary content and receive accurate answers based on actual data.
|
| 15 |
+
|
| 16 |
+
## β¨ Key Features
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
## ποΈ System Architecture
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
|
| 23 |
+
β Streamlit UI β β FastAPI β β Vector β
|
| 24 |
+
β (Frontend) βββββΊβ Backend βββββΊβ Database β
|
| 25 |
+
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
|
| 26 |
+
β
|
| 27 |
+
βΌ
|
| 28 |
+
βββββββββββββββββββ
|
| 29 |
+
β RAG Engine β
|
| 30 |
+
β (LLM + β
|
| 31 |
+
β Retrieval) β
|
| 32 |
+
βββββββββββββββββββ
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## π Installation and Setup
|
| 36 |
+
|
| 37 |
+
### System Requirements
|
| 38 |
+
|
| 39 |
+
### Install Dependencies
|
| 40 |
+
```bash
|
| 41 |
+
# Create virtual environment
|
| 42 |
+
python -m venv .venv
|
| 43 |
+
|
| 44 |
+
# Activate virtual environment
|
| 45 |
+
# Windows
|
| 46 |
+
.venv\Scripts\activate
|
| 47 |
+
# Linux/Mac
|
| 48 |
+
source .venv/bin/activate
|
| 49 |
+
|
| 50 |
+
# Install packages
|
| 51 |
+
pip install -r requirements.txt
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### Environment Configuration
|
| 55 |
+
|
| 56 |
+
Create a `.env` file in the project root directory with the following structure:
|
| 57 |
+
|
| 58 |
+
```env
|
| 59 |
+
# API Keys
|
| 60 |
+
OPENAI_API_KEY=your_openai_api_key_here
|
| 61 |
+
GOOGLE_API_KEY=your_google_api_key_here
|
| 62 |
+
ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
| 63 |
+
|
| 64 |
+
# Database Configuration
|
| 65 |
+
DATABASE_URL=sqlite:///./user_database/auth.db
|
| 66 |
+
VECTOR_DB_PATH=./VectorDB
|
| 67 |
+
|
| 68 |
+
# Model Configuration
|
| 69 |
+
EMBEDDING_MODEL=google-universal-sentence-encoder
|
| 70 |
+
LLM_MODEL=gpt-3.5-turbo
|
| 71 |
+
CHUNK_SIZE=1000
|
| 72 |
+
CHUNK_OVERLAP=200
|
| 73 |
+
|
| 74 |
+
# Server Configuration
|
| 75 |
+
RAG_SERVICE_PORT=8001
|
| 76 |
+
STREAMLIT_PORT=8501
|
| 77 |
+
FASTAPI_PORT=8000
|
| 78 |
+
|
| 79 |
+
# Security
|
| 80 |
+
SECRET_KEY=your_secret_key_here
|
| 81 |
+
JWT_SECRET=your_jwt_secret_here
|
| 82 |
+
|
| 83 |
+
# Logging
|
| 84 |
+
LOG_LEVEL=INFO
|
| 85 |
+
LOG_FILE=./logs/app.log
|
| 86 |
+
|
| 87 |
+
# Vector Database
|
| 88 |
+
CHROMA_DB_PATH=./VectorDB
|
| 89 |
+
PERSIST_DIRECTORY=./VectorDB
|
| 90 |
+
|
| 91 |
+
# File Processing
|
| 92 |
+
SUPPORTED_FORMATS=pdf,docx,txt,md
|
| 93 |
+
MAX_FILE_SIZE=10485760
|
| 94 |
+
TEMP_DIR=./temp
|
| 95 |
+
|
| 96 |
+
# RAG Configuration
|
| 97 |
+
TOP_K_RESULTS=5
|
| 98 |
+
SIMILARITY_THRESHOLD=0.7
|
| 99 |
+
MAX_TOKENS=4096
|
| 100 |
+
TEMPERATURE=0.7
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
**Important Notes:**
|
| 104 |
+
|
| 105 |
+
### Run the Application
|
| 106 |
+
|
| 107 |
+
#### 1. Start RAG Service
|
| 108 |
+
```bash
|
| 109 |
+
python start_rag_service.py
|
| 110 |
+
```
|
| 111 |
+
Service will run at: http://127.0.0.1:8001
|
| 112 |
+
|
| 113 |
+
#### 2. Start Streamlit UI
|
| 114 |
+
```bash
|
| 115 |
+
cd src/streamlit_app
|
| 116 |
+
streamlit run interface.py
|
| 117 |
+
```
|
| 118 |
+
UI will run at: http://localhost:8501
|
| 119 |
+
|
| 120 |
+
## π Directory Structure
|
| 121 |
+
|
| 122 |
+
```
|
| 123 |
+
RAG-Personal-Diary-Chatbot/
|
| 124 |
+
βββ src/
|
| 125 |
+
β βββ Indexingstep/ # Data indexing pipeline
|
| 126 |
+
β βββ Retrivel_And_Generation/ # RAG engine
|
| 127 |
+
β βββ rag_service/ # FastAPI backend
|
| 128 |
+
β βββ streamlit_app/ # User interface
|
| 129 |
+
β βββ VectorDB/ # Vector database
|
| 130 |
+
βββ notebook/ # Jupyter notebooks
|
| 131 |
+
βββ tests/ # Unit tests
|
| 132 |
+
βββ images/ # Documentation images
|
| 133 |
+
βββ start_rag_service.py # Service startup script
|
| 134 |
+
βββ .env # Environment variables (create from template)
|
| 135 |
+
βββ env_template.txt # Environment variables template
|
| 136 |
+
βββ README.md
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
## π§ Configuration
|
| 140 |
+
|
| 141 |
+
### Vector Database
|
| 142 |
+
|
| 143 |
+
### AI Models
|
| 144 |
+
|
| 145 |
+
## π Performance
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
## π§ͺ Testing
|
| 149 |
+
|
| 150 |
+
```bash
|
| 151 |
+
# Run all tests
|
| 152 |
+
python -m pytest tests/
|
| 153 |
+
|
| 154 |
+
# Run specific test
|
| 155 |
+
python -m pytest tests/test_rag_system.py
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
## π€ Contributing
|
| 159 |
+
|
| 160 |
+
1. Fork the project
|
| 161 |
+
2. Create feature branch (`git checkout -b feature/AmazingFeature`)
|
| 162 |
+
3. Commit changes (`git commit -m 'Add some AmazingFeature'`)
|
| 163 |
+
4. Push to branch (`git push origin feature/AmazingFeature`)
|
| 164 |
+
5. Open Pull Request
|
| 165 |
+
|
| 166 |
+
## π License
|
| 167 |
+
|
| 168 |
+
This project is distributed under the MIT License. See the `LICENSE` file for more details.
|
| 169 |
+
|
| 170 |
+
## π Contact
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
## π Acknowledgments
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
## π Project Description
|
| 177 |
+
|
| 178 |
+
RAG Personal Diary Chatbot is an intelligent chatbot application that leverages Retrieval-Augmented Generation (RAG) architecture to interact with users' personal diaries. Users can ask questions about their diary content and receive accurate, context-based answers.
|
| 179 |
+
|
| 180 |
+
## β¨ Key Features
|
| 181 |
+
|
| 182 |
+
- **Diary Indexing**: Automatically processes and indexes diary files (PDF, DOCX, TXT)
|
| 183 |
+
- **Semantic Search**: Uses a vector database for semantic search
|
| 184 |
+
- **AI Chatbot**: Natural interaction with diary data
|
| 185 |
+
- **User Isolation**: Each user has a separate vector database
|
| 186 |
+
- **Web Interface**: Easy-to-use Streamlit UI
|
| 187 |
+
- **REST API**: FastAPI backend for integration
|
| 188 |
+
|
| 189 |
+
## ποΈ System Architecture
|
| 190 |
+
|
| 191 |
+
```
|
| 192 |
+
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
|
| 193 |
+
β Streamlit UI βββββΊβ FastAPI βββββΊβ Vector DB β
|
| 194 |
+
β (Frontend) β β Backend β β (ChromaDB) β
|
| 195 |
+
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
|
| 196 |
+
β
|
| 197 |
+
βΌ
|
| 198 |
+
βββββββββββββββββ
|
| 199 |
+
β RAG Engine β
|
| 200 |
+
β (LLM + β
|
| 201 |
+
β Retrieval) β
|
| 202 |
+
βββββββββββββββββ
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
## π Installation and Setup
|
| 206 |
+
|
| 207 |
+
### System Requirements
|
| 208 |
+
|
| 209 |
+
- Python 3.8+
|
| 210 |
+
|
| 211 |
+
### Install Dependencies
|
| 212 |
+
|
| 213 |
+
```bash
|
| 214 |
+
# Create virtual environment
|
| 215 |
+
python -m venv .venv
|
| 216 |
+
|
| 217 |
+
# Activate virtual environment
|
| 218 |
+
# Windows
|
| 219 |
+
.venv\Scripts\activate
|
| 220 |
+
# Linux/Mac
|
| 221 |
+
source .venv/bin/activate
|
| 222 |
+
|
| 223 |
+
# Install packages
|
| 224 |
+
pip install -r requirements.txt
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
### Environment Configuration
|
| 228 |
+
|
| 229 |
+
Create a `.env` file in the project root directory with the following structure:
|
| 230 |
+
|
| 231 |
+
```env
|
| 232 |
+
# Google API Configuration for RAG System
|
| 233 |
+
GOOGLE_API_KEY=[Google API key]
|
| 234 |
+
|
| 235 |
+
# Database Configuration
|
| 236 |
+
DATABASE_PATH=./src/streamlit_app/backend/diary.db
|
| 237 |
+
|
| 238 |
+
# Vector Database Configuration
|
| 239 |
+
VECTOR_DB_PATH=./src/Indexingstep/diary_vector_db_enhanced
|
| 240 |
+
COLLECTION_NAME=diary_entries
|
| 241 |
+
|
| 242 |
+
# RAG Configuration
|
| 243 |
+
EMBEDDING_MODEL=models/embedding-001
|
| 244 |
+
CHAT_MODEL=gemini-2.5-flash
|
| 245 |
+
```
|
| 246 |
+
|
| 247 |
+
**Important Notes:**
|
| 248 |
+
- Replace all placeholder values with your actual API keys and configuration
|
| 249 |
+
- Keep your `.env` file secure and never commit it to version control
|
| 250 |
+
- The `.env` file is already included in `.gitignore`
|
| 251 |
+
- Use `env_template.txt` as a reference to create your `.env` file
|
| 252 |
+
|
| 253 |
+
### Run the Application
|
| 254 |
+
|
| 255 |
+
```bash
|
| 256 |
+
# Start the RAG backend service
|
| 257 |
+
python start_rag_service.py
|
| 258 |
+
|
| 259 |
+
# Start the Streamlit UI
|
| 260 |
+
streamlit run src/streamlit_app/interface.py
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
## π Directory Structure
|
| 264 |
+
|
| 265 |
+
```
|
| 266 |
+
RAG-Personal-Diary-Chatbot/
|
| 267 |
+
βββ src/
|
| 268 |
+
β βββ Indexingstep/ # Data indexing pipeline
|
| 269 |
+
β βββ Retrivel_And_Generation/ # RAG engine
|
| 270 |
+
β βββ rag_service/ # FastAPI backend
|
| 271 |
+
β βββ streamlit_app/ # User interface
|
| 272 |
+
β βββ VectorDB/ # Vector database
|
| 273 |
+
βββ notebook/ # Jupyter notebooks
|
| 274 |
+
βββ tests/ # Unit tests
|
| 275 |
+
βββ images/ # Documentation images
|
| 276 |
+
βββ start_rag_service.py # Service startup script
|
| 277 |
+
βββ .env # Environment variables (create from template)
|
| 278 |
+
βββ env_template.txt # Environment variables template
|
| 279 |
+
βββ README.md
|
| 280 |
+
```
|
| 281 |
+
|
| 282 |
+
## π§ Configuration
|
| 283 |
+
|
| 284 |
+
### Vector Database
|
| 285 |
+
- **ChromaDB**: Main database for vector embeddings
|
| 286 |
+
- **Chunk size**: 1000 characters (customizable)
|
| 287 |
+
- **Overlap**: 200 characters between chunks
|
| 288 |
+
|
| 289 |
+
### AI Models
|
| 290 |
+
- **Embedding**: Google's Universal Sentence Encoder
|
| 291 |
+
- **LLM**: Google Gemini (can be replaced with other models)
|
| 292 |
+
|
| 293 |
+
## π Performance
|
| 294 |
+
|
| 295 |
+
- **Processing time**: ~2-5 seconds per question
|
| 296 |
+
- **Accuracy**: 85-95% depending on data quality
|
| 297 |
+
- **Scalability**: Supports thousands of diaries
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
## π€ Contributing
|
| 301 |
+
|
| 302 |
+
1. Fork the project
|
| 303 |
+
2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
|
| 304 |
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
| 305 |
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
| 306 |
+
5. Open a Pull Request
|
| 307 |
+
## π Contact
|
| 308 |
+
|
| 309 |
+
- **Author**: [DongAnh]
|
| 310 |
+
- **Email**: [donganhng098@gmail.com]
|
| 311 |
+
- **GitHub**: [github.com/DongAnh]
|
| 312 |
+
|
| 313 |
+
## π Acknowledgments
|
| 314 |
+
|
| 315 |
+
- Gemini for GPT models
|
| 316 |
+
- Google for Universal Sentence Encoder
|
| 317 |
+
- ChromaDB team for vector database
|
| 318 |
+
- FastAPI and Streamlit communities
|
| 319 |
+
- RAG architecture
|