Spaces:
Sleeping
Sleeping
Upload README.md
Browse files
README.md
CHANGED
|
@@ -1,11 +1,103 @@
|
|
| 1 |
---
|
| 2 |
-
title: Chatbot
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Personalized Chatbot API
|
| 3 |
+
emoji: 🤖
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Personalized Chatbot Backend
|
| 12 |
+
|
| 13 |
+
FastAPI backend for a personalized chatbot with Human-in-the-Loop (HITL) feedback.
|
| 14 |
+
|
| 15 |
+
## Features
|
| 16 |
+
|
| 17 |
+
- 🚀 Fast inference with Llama 3.2
|
| 18 |
+
- 💾 Feedback collection for continuous learning
|
| 19 |
+
- 📊 Statistics tracking
|
| 20 |
+
- 🔧 LoRA adapter support for finetuned models
|
| 21 |
+
|
| 22 |
+
## API Endpoints
|
| 23 |
+
|
| 24 |
+
### POST /chat
|
| 25 |
+
Generate chatbot response
|
| 26 |
+
|
| 27 |
+
**Request:**
|
| 28 |
+
```json
|
| 29 |
+
{
|
| 30 |
+
"message": "Hello, how are you?",
|
| 31 |
+
"history": [],
|
| 32 |
+
"max_length": 200,
|
| 33 |
+
"temperature": 0.7
|
| 34 |
+
}
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
**Response:**
|
| 38 |
+
```json
|
| 39 |
+
{
|
| 40 |
+
"reply": "I'm doing well, thank you!",
|
| 41 |
+
"timestamp": 1234567890.123
|
| 42 |
+
}
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
### POST /feedback
|
| 46 |
+
Submit correction for model response
|
| 47 |
+
|
| 48 |
+
**Request:**
|
| 49 |
+
```json
|
| 50 |
+
{
|
| 51 |
+
"user_input": "What is the capital of France?",
|
| 52 |
+
"model_reply": "The capital is Berlin",
|
| 53 |
+
"user_correction": "The capital is Paris",
|
| 54 |
+
"reason": "incorrect_answer"
|
| 55 |
+
}
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
### GET /stats
|
| 59 |
+
Get feedback statistics
|
| 60 |
+
|
| 61 |
+
**Response:**
|
| 62 |
+
```json
|
| 63 |
+
{
|
| 64 |
+
"total_interactions": 100,
|
| 65 |
+
"corrections": 15,
|
| 66 |
+
"accepted": 85,
|
| 67 |
+
"correction_rate": 0.15
|
| 68 |
+
}
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### GET /health
|
| 72 |
+
Health check endpoint
|
| 73 |
+
|
| 74 |
+
## Configuration
|
| 75 |
+
|
| 76 |
+
The model is configured in the `startup_event()` function:
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
model_manager.initialize(
|
| 80 |
+
model_name="meta-llama/Llama-3.2-1B-Instruct",
|
| 81 |
+
adapter_path=None, # Path to LoRA adapter if finetuned
|
| 82 |
+
use_4bit=True # Use 4-bit quantization
|
| 83 |
+
)
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## Usage
|
| 87 |
+
|
| 88 |
+
1. Fork this Space
|
| 89 |
+
2. Modify `model_name` and `adapter_path` in `app.py` if needed
|
| 90 |
+
3. The API will be available at: `https://YOUR-USERNAME-chatbot-api.hf.space`
|
| 91 |
+
|
| 92 |
+
## Local Development
|
| 93 |
+
|
| 94 |
+
```bash
|
| 95 |
+
pip install -r requirements.txt
|
| 96 |
+
python app.py
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
API will be available at: http://localhost:7860
|
| 100 |
+
|
| 101 |
+
## License
|
| 102 |
+
|
| 103 |
+
MIT
|