Spaces:
Sleeping
Sleeping
File size: 8,710 Bytes
a4c8c42 d971cfc a4c8c42 2fabc4b a4c8c42 |
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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
---
title: ๐๐ก๐๐ญ ๐๐ฎ๐ฆ๐จ๐ฎ๐ซ ๐๐๐ ๐.๐๐
emoji: ๐จ
colorFrom: purple
colorTo: yellow
sdk: docker
pinned: false
---
# ๐ง DNAI Humour Chatbot - Interactive Web Interface
A beautiful, fully-functional chat interface for the **dnai-humour-0.5B-instruct** model. Chat with a witty, lightweight AI assistant that's fast, friendly, and surprisingly capable.

---
## โจ Features
- ๐ฌ **Real-time Chat** - Smooth, responsive conversation interface
- ๐จ **Beautiful UI** - Modern design with dark/light mode
- โก **Fast Responses** - Optimized for 0.5B parameter model
- ๐ญ **Personality** - Witty and helpful, not robotic
- ๐ฑ **Responsive** - Works on all devices
- ๐งน **Clean UX** - Clear conversations, suggestions, timestamps
---
## ๐ Quick Start
### Prerequisites
- Python 3.8+
- CUDA-capable GPU (recommended) or CPU
- 2GB+ VRAM (GPU) or 4GB+ RAM (CPU)
### Installation
1. **Clone the Space**
```bash
git clone https://huggingface.co/spaces/YOUR-USERNAME/dnai-humour-chatbot
cd dnai-humour-chatbot
```
2. **Install Dependencies**
```bash
pip install -r requirements.txt
```
3. **Run the Application**
```bash
uvicorn app:app --host 0.0.0.0 --port 7860
```
4. **Open Browser**
```
http://localhost:7860
```
---
## ๐ Deploy to Hugging Face Spaces
### Step 1: Create Space
1. Go to [Hugging Face](https://huggingface.co/)
2. Click **New Space**
3. Settings:
- **Name**: `dnai-humour-chatbot`
- **SDK**: Docker
- **Hardware**: T4 Small (or CPU basic for testing)
- **Visibility**: Public
### Step 2: Upload Files
Upload these files to your Space:
```
dnai-humour-chatbot/
โโโ app.py
โโโ requirements.txt
โโโ index.html
โโโ README.md
โโโ Dockerfile (optional)
```
### Step 3: Create Dockerfile (if needed)
```dockerfile
FROM python:3.10-slim
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application
COPY . .
# Expose port
EXPOSE 7860
# Run
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
```
### Step 4: Wait for Build
- Hugging Face will automatically build your Space
- Check logs for any errors
- Model will download on first startup (~500MB)
- Once "Running", your chatbot is live! ๐
---
## ๐ File Structure
```
dnai-humour-chatbot/
โ
โโโ app.py # FastAPI backend with model inference
โ โโโ /api/chat # POST - Send messages
โ โโโ /api/info # GET - Model information
โ โโโ /health # GET - Health check
โ โโโ /api/reset # POST - Reset conversation
โ
โโโ index.html # React-based chat interface
โ โโโ Message history
โ โโโ Dark/Light mode
โ โโโ Typing indicators
โ โโโ Quick suggestions
โ
โโโ requirements.txt # Python dependencies
โ โโโ transformers
โ โโโ torch
โ โโโ fastapi
โ โโโ uvicorn
โ
โโโ README.md # This file
```
---
## ๐ API Documentation
### POST `/api/chat`
**Request:**
```json
{
"messages": [
{
"role": "user",
"content": "Tell me a joke"
}
],
"temperature": 0.7,
"max_tokens": 256
}
```
**Response:**
```json
{
"response": "Why don't scientists trust atoms? Because they make up everything! ๐",
"model": "DarkNeuron-AI/dnai-humour-0.5B-instruct",
"tokens_used": 45
}
```
### GET `/api/info`
**Response:**
```json
{
"model_name": "DNAI Humour 0.5B Instruct",
"version": "1.0",
"base_model": "Qwen2.5-0.5B-Instruct",
"parameters": "~0.5 Billion",
"capabilities": [
"Instruction following",
"Conversational AI",
"Light humor",
"Low-latency responses"
]
}
```
---
## ๐จ UI Features
### Chat Interface
- Clean, modern design
- Message bubbles with timestamps
- User/Assistant avatars
- Smooth animations
### Dark/Light Mode
- Toggle between themes
- Smooth transitions
- Persistent preferences (client-side)
### Smart Suggestions
- Quick-start prompts
- Contextual examples
- One-click input
### Typing Indicators
- Real-time feedback
- Loading animations
- Response timing
---
## โ๏ธ Configuration
### Model Parameters (app.py)
```python
MODEL_NAME = "DarkNeuron-AI/dnai-humour-0.5B-instruct"
MAX_LENGTH = 512 # Context window
TEMPERATURE = 0.7 # Creativity (0.0-1.0)
TOP_P = 0.9 # Nucleus sampling
TOP_K = 50 # Top-k sampling
```
### Generation Settings
Adjust in `/api/chat` request:
- `temperature`: 0.1 (focused) to 1.0 (creative)
- `max_tokens`: 50 (short) to 512 (long)
- `stream`: true/false (streaming support)
---
## ๐ Troubleshooting
### Issue: Model not loading
**Symptoms**: 503 errors, "Model not loaded"
**Solutions**:
```bash
# Check CUDA availability
python -c "import torch; print(torch.cuda.is_available())"
# Verify model download
python -c "from transformers import AutoModelForCausalLM; AutoModelForCausalLM.from_pretrained('DarkNeuron-AI/dnai-humour-0.5B-instruct')"
# Check logs
uvicorn app:app --log-level debug
```
### Issue: Out of memory
**Solutions**:
1. Reduce `max_tokens` in generation
2. Use CPU instead of GPU (slower but works)
3. Enable model quantization (INT8)
```python
# In app.py, modify model loading:
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
load_in_8bit=True, # Enable INT8 quantization
device_map="auto"
)
```
### Issue: Slow responses
**Solutions**:
1. Use GPU instead of CPU
2. Reduce `max_tokens`
3. Lower `temperature` for faster sampling
4. Use smaller batch size
---
## ๐ Performance Benchmarks
| Hardware | Response Time | Memory Usage |
|----------|--------------|--------------|
| T4 GPU | ~1-2s | ~2GB VRAM |
| CPU | ~5-10s | ~4GB RAM |
| A10G GPU | ~0.5-1s | ~2GB VRAM |
---
## ๐ฏ Use Cases
- **Educational Chatbots** - Learning companions
- **Personal Assistants** - Quick help & info
- **Code Helpers** - Programming Q&A
- **Creative Writing** - Brainstorming & ideas
- **General Chat** - Friendly conversation
---
## ๐ซ Limitations
- **Not for production medical/legal advice**
- **Limited context window** (512 tokens)
- **0.5B parameters** - expect occasional mistakes
- **No long-term memory** - each conversation is independent
- **English-focused** - other languages may be limited
---
## ๐ Privacy & Safety
- **No data logging** - conversations not stored
- **Local processing** - your data stays with you
- **No tracking** - no analytics or monitoring
- **Open source** - fully transparent code
---
## ๐ ๏ธ Advanced Customization
### Change Model Personality
Edit the system prompt in `app.py`:
```python
def format_chat_prompt(messages: List[Message]) -> str:
system_prompt = "You are a helpful, witty AI assistant."
formatted_messages = [f"System: {system_prompt}"]
# ... rest of code
```
### Add Memory
Implement conversation history storage:
```python
# Simple in-memory storage
conversations = {}
@app.post("/api/chat")
async def chat(request: ChatRequest, user_id: str = "default"):
if user_id not in conversations:
conversations[user_id] = []
# ... use stored history
```
### Enable Streaming
For real-time token-by-token responses:
```python
from fastapi.responses import StreamingResponse
@app.post("/api/chat/stream")
async def chat_stream(request: ChatRequest):
def generate():
# Yield tokens as they're generated
for token in model.generate_stream(...):
yield f"data: {token}\n\n"
return StreamingResponse(generate(), media_type="text/event-stream")
```
---
## ๐ Support
For issues, questions, or suggestions:
- Open an issue on GitHub
- Contact via Hugging Face
- Check model card: [DarkNeuron-AI/dnai-humour-0.5B-instruct](https://huggingface.co/DarkNeuron-AI/dnai-humour-0.5B-instruct)
---
## ๐ Acknowledgments
- **Base Model**: Qwen2.5-0.5B-Instruct by Alibaba
- **Dataset**: OpenAssistant v1
- **Framework**: Hugging Face Transformers
- **UI**: React + Tailwind CSS
---
## ๐ License
MIT License - Free to use, modify, and distribute
---
<div align="center">
**Crafted with โค๏ธ and passion by @MADARA369Uchiha**
*Small brain, well-trained. Fast responses, good vibes.* โจ
[](https://huggingface.co/DarkNeuron-AI)
[](https://github.com/Madara369Uchiha)
</div> |