Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
@@ -8,3 +8,331 @@ pinned: false
|
|
8 |
---
|
9 |
|
10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
---
|
9 |
|
10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
11 |
+
|
12 |
+
---
|
13 |
+
Di frontend production
|
14 |
+
Endpoint Hugging Face yang Tersedia:
|
15 |
+
Base URL: https://lyon28-ai-character-chat.hf.space/inference
|
16 |
+
Models yang Supported:
|
17 |
+
Lyon28/Tinny-Llama
|
18 |
+
Lyon28/Pythia
|
19 |
+
Lyon28/Bert-Tinny
|
20 |
+
Lyon28/Albert-Base-V2
|
21 |
+
Lyon28/T5-Small
|
22 |
+
Lyon28/GPT-2
|
23 |
+
Lyon28/GPT-Neo
|
24 |
+
Lyon28/Distilbert-Base-Uncased
|
25 |
+
Lyon28/Distil_GPT-2
|
26 |
+
Lyon28/GPT-2-Tinny
|
27 |
+
Lyon28/Electra-Small
|
28 |
+
|
29 |
+
---
|
30 |
+
# Character AI Chat - CPU Optimized Backend
|
31 |
+
|
32 |
+
🎭 **Advanced Character AI Chat System** dengan dukungan 11 model AI yang dioptimalkan untuk CPU, dilengkapi dengan sistem roleplay canggih, memori percakapan, dan kecerdasan emosional.
|
33 |
+
|
34 |
+
## ✨ Fitur Utama
|
35 |
+
|
36 |
+
### 🧠 Multi-Model AI Support
|
37 |
+
- **11 Model AI** yang dioptimalkan untuk CPU
|
38 |
+
- Mendukung berbagai jenis task: Text Generation, Classification, Text2Text
|
39 |
+
- Auto-loading dengan lazy initialization untuk performa optimal
|
40 |
+
|
41 |
+
### 🎭 Advanced Roleplay System
|
42 |
+
- **Conversation Memory** - Mengingat percakapan sebelumnya
|
43 |
+
- **Dynamic Personality** - Karakter yang berkembang seiring waktu
|
44 |
+
- **Emotional Intelligence** - Mendeteksi dan merespons emosi user
|
45 |
+
- **Character Development** - Belajar preferensi dan adaptasi gaya bicara
|
46 |
+
- **Roleplay Actions** - Aksi fisik dan emosional yang kontekstual
|
47 |
+
- **Relationship Tracking** - Level hubungan yang berkembang
|
48 |
+
|
49 |
+
### 🌟 Enhanced Features
|
50 |
+
- **Situational Context** - Respons disesuaikan dengan situasi dan lokasi
|
51 |
+
- **Indonesian Language Optimized** - Dioptimalkan untuk bahasa Indonesia
|
52 |
+
- **Session Management** - Multiple session dengan memori terpisah
|
53 |
+
- **Real-time Processing** - Response time tracking
|
54 |
+
- **Fallback System** - Sistem backup untuk handling error
|
55 |
+
|
56 |
+
## 🚀 Model yang Didukung
|
57 |
+
|
58 |
+
### ⚡ Priority 1 (Ultra Fast)
|
59 |
+
- **DistilGPT-2** - Text generation ringan dan cepat
|
60 |
+
- **GPT-2 Tinny** - Versi kompak GPT-2
|
61 |
+
- **BERT Tinny** - Text classification ringan
|
62 |
+
- **DistilBERT** - Classification model yang efisien
|
63 |
+
|
64 |
+
### 🔥 Priority 2 (Balanced)
|
65 |
+
- **ALBERT Base** - Advanced text understanding
|
66 |
+
- **ELECTRA Small** - Efficient pre-training model
|
67 |
+
- **T5 Small** - Text-to-text generation
|
68 |
+
- **GPT-2 Standard** - Standard GPT-2 model
|
69 |
+
|
70 |
+
### 💪 Priority 3 (Advanced)
|
71 |
+
- **Tinny Llama** - Compact large language model
|
72 |
+
- **Pythia** - Research-grade model
|
73 |
+
- **GPT-Neo** - Open-source GPT alternative
|
74 |
+
|
75 |
+
## 📋 Persyaratan Sistem
|
76 |
+
|
77 |
+
### Software Requirements
|
78 |
+
```
|
79 |
+
Python 3.8+
|
80 |
+
FastAPI
|
81 |
+
Transformers
|
82 |
+
PyTorch (CPU version)
|
83 |
+
Uvicorn
|
84 |
+
```
|
85 |
+
|
86 |
+
### Hardware Requirements
|
87 |
+
- **CPU**: Multi-core processor (minimum 4 cores recommended)
|
88 |
+
- **RAM**: 8GB minimum, 16GB recommended
|
89 |
+
- **Storage**: 10GB free space untuk model cache
|
90 |
+
- **Platform**: Windows, macOS, Linux
|
91 |
+
|
92 |
+
## 🛠️ Instalasi
|
93 |
+
|
94 |
+
### 1. Clone Repository
|
95 |
+
```bash
|
96 |
+
git clone <repository-url>
|
97 |
+
cd character-ai-chat
|
98 |
+
```
|
99 |
+
|
100 |
+
### 2. Install Dependencies
|
101 |
+
```bash
|
102 |
+
pip install -r requirements.txt
|
103 |
+
```
|
104 |
+
|
105 |
+
### 3. Setup Environment
|
106 |
+
```bash
|
107 |
+
# Optional: Set cache directory
|
108 |
+
export HF_HOME=/path/to/cache
|
109 |
+
export TRANSFORMERS_CACHE=/path/to/cache
|
110 |
+
```
|
111 |
+
|
112 |
+
### 4. Prepare Assets
|
113 |
+
Pastikan file berikut ada di root directory:
|
114 |
+
- `index.html` - Frontend interface
|
115 |
+
- `avatar.png` - Character avatar (optional)
|
116 |
+
- `background.png` - Background image (optional)
|
117 |
+
|
118 |
+
### 5. Run Application
|
119 |
+
```bash
|
120 |
+
python app.py
|
121 |
+
```
|
122 |
+
|
123 |
+
Aplikasi akan berjalan di: `http://localhost:7860`
|
124 |
+
|
125 |
+
## 🎮 Cara Penggunaan
|
126 |
+
|
127 |
+
### Basic Chat
|
128 |
+
```python
|
129 |
+
import requests
|
130 |
+
|
131 |
+
response = requests.post("http://localhost:7860/chat", json={
|
132 |
+
"message": "Hai, apa kabar?",
|
133 |
+
"model": "distil-gpt-2",
|
134 |
+
"char_name": "Sayang",
|
135 |
+
"user_name": "Kamu",
|
136 |
+
"situation": "Santai",
|
137 |
+
"location": "Ruang tamu"
|
138 |
+
})
|
139 |
+
|
140 |
+
print(response.json()["response"])
|
141 |
+
```
|
142 |
+
|
143 |
+
### Advanced Usage dengan Session
|
144 |
+
```python
|
145 |
+
# Chat dengan session tracking
|
146 |
+
response = requests.post("http://localhost:7860/chat", json={
|
147 |
+
"message": "Aku sedang sedih hari ini",
|
148 |
+
"model": "gpt-2",
|
149 |
+
"char_name": "Luna",
|
150 |
+
"user_name": "Alex",
|
151 |
+
"situation": "Romantis",
|
152 |
+
"location": "Taman",
|
153 |
+
"session_id": "user_123"
|
154 |
+
})
|
155 |
+
```
|
156 |
+
|
157 |
+
### Cek Memory Session
|
158 |
+
```python
|
159 |
+
# Lihat conversation memory
|
160 |
+
memory = requests.get("http://localhost:7860/memory/user_123")
|
161 |
+
print(memory.json())
|
162 |
+
|
163 |
+
# Lihat personality development
|
164 |
+
personality = requests.get("http://localhost:7860/personality/user_123")
|
165 |
+
print(personality.json())
|
166 |
+
```
|
167 |
+
|
168 |
+
## 🌐 API Endpoints
|
169 |
+
|
170 |
+
### Core Endpoints
|
171 |
+
- `POST /chat` - Main chat endpoint
|
172 |
+
- `GET /models` - List available models
|
173 |
+
- `GET /health` - Health check
|
174 |
+
- `GET /config` - Configuration info
|
175 |
+
|
176 |
+
### Enhanced Features
|
177 |
+
- `GET /memory/{session_id}` - Get conversation memory
|
178 |
+
- `GET /personality/{session_id}` - Get character personality
|
179 |
+
- `DELETE /session/{session_id}` - Reset session data
|
180 |
+
|
181 |
+
### Utility Endpoints
|
182 |
+
- `GET /verify-models` - Verify all models loading
|
183 |
+
- `POST /inference` - Alternative inference endpoint
|
184 |
+
- `GET /api` - API documentation
|
185 |
+
|
186 |
+
## 🎨 Kustomisasi Karakter
|
187 |
+
|
188 |
+
### Personality Traits
|
189 |
+
Karakter memiliki 5 trait utama yang dapat disesuaikan:
|
190 |
+
```python
|
191 |
+
personality.traits = {
|
192 |
+
"extraversion": 0.7, # Seberapa ekstrovert (0-1)
|
193 |
+
"agreeableness": 0.8, # Seberapa mudah setuju (0-1)
|
194 |
+
"conscientiousness": 0.6, # Seberapa teliti (0-1)
|
195 |
+
"neuroticism": 0.3, # Seberapa cemas (0-1)
|
196 |
+
"openness": 0.7 # Seberapa terbuka (0-1)
|
197 |
+
}
|
198 |
+
```
|
199 |
+
|
200 |
+
### Speaking Styles
|
201 |
+
- `casual_friendly` - Santai dan ramah
|
202 |
+
- `romantic_caring` - Romantis dan perhatian
|
203 |
+
- `supportive_warm` - Supportif dan hangat
|
204 |
+
- `playful_teasing` - Main-main dan menggoda
|
205 |
+
|
206 |
+
### Situasi yang Didukung
|
207 |
+
- **Santai** - Obrolan santai sehari-hari
|
208 |
+
- **Romantis** - Suasana romantis dan intim
|
209 |
+
- **Sedih** - Memberikan dukungan emosional
|
210 |
+
- **Excited** - Berbagi kegembiraan
|
211 |
+
- **Study** - Membantu belajar
|
212 |
+
- **Gaming** - Ngobrol tentang games
|
213 |
+
|
214 |
+
## 🔧 Optimisasi CPU
|
215 |
+
|
216 |
+
### Memory Management
|
217 |
+
```python
|
218 |
+
# CPU thread optimization
|
219 |
+
torch.set_num_threads(2)
|
220 |
+
os.environ['OMP_NUM_THREADS'] = '2'
|
221 |
+
os.environ['MKL_NUM_THREADS'] = '2'
|
222 |
+
|
223 |
+
# Memory cleanup
|
224 |
+
gc.collect()
|
225 |
+
```
|
226 |
+
|
227 |
+
### Model Loading Strategy
|
228 |
+
- **Lazy Loading** - Model dimuat saat pertama kali digunakan
|
229 |
+
- **Shared Pipelines** - Reuse pipeline untuk efisiensi
|
230 |
+
- **Cache Management** - Automatic cache cleanup
|
231 |
+
|
232 |
+
## 📊 Performance Monitoring
|
233 |
+
|
234 |
+
### Response Time Tracking
|
235 |
+
Setiap response dilengkapi dengan informasi performa:
|
236 |
+
```json
|
237 |
+
{
|
238 |
+
"response": "Hai! Apa kabar?",
|
239 |
+
"processing_time": "450ms",
|
240 |
+
"model": "DistilGPT-2 ⚡",
|
241 |
+
"status": "success"
|
242 |
+
}
|
243 |
+
```
|
244 |
+
|
245 |
+
### Memory Usage
|
246 |
+
```python
|
247 |
+
# Check memory usage
|
248 |
+
GET /health
|
249 |
+
{
|
250 |
+
"loaded_models": 5,
|
251 |
+
"memory_usage": "2.1GB",
|
252 |
+
"optimization": "Character AI CPU-Tuned"
|
253 |
+
}
|
254 |
+
```
|
255 |
+
|
256 |
+
## 🐛 Troubleshooting
|
257 |
+
|
258 |
+
### Common Issues
|
259 |
+
|
260 |
+
**Model Loading Error**
|
261 |
+
```bash
|
262 |
+
# Solution: Clear cache
|
263 |
+
rm -rf /tmp/.cache/huggingface
|
264 |
+
```
|
265 |
+
|
266 |
+
**Out of Memory**
|
267 |
+
```python
|
268 |
+
# Reduce max_length
|
269 |
+
request.max_length = 100
|
270 |
+
|
271 |
+
# Use lighter models
|
272 |
+
model = "distil-gpt-2" # instead of "gpt-neo"
|
273 |
+
```
|
274 |
+
|
275 |
+
**Slow Response**
|
276 |
+
```python
|
277 |
+
# Use priority 1 models for faster response
|
278 |
+
recommended_models = ["distil-gpt-2", "gpt-2-tinny", "bert-tinny"]
|
279 |
+
```
|
280 |
+
|
281 |
+
### Debug Mode
|
282 |
+
```bash
|
283 |
+
# Run with debug logging
|
284 |
+
PYTHONPATH=. python -m uvicorn app:app --reload --log-level debug
|
285 |
+
```
|
286 |
+
|
287 |
+
## 🤝 Contributing
|
288 |
+
|
289 |
+
### Development Setup
|
290 |
+
```bash
|
291 |
+
# Install development dependencies
|
292 |
+
pip install -r requirements-dev.txt
|
293 |
+
|
294 |
+
# Run tests
|
295 |
+
python -m pytest tests/
|
296 |
+
|
297 |
+
# Code formatting
|
298 |
+
black app.py
|
299 |
+
flake8 app.py
|
300 |
+
```
|
301 |
+
|
302 |
+
### Adding New Models
|
303 |
+
1. Tambahkan model config di `MODELS` dictionary
|
304 |
+
2. Test dengan `/verify-models` endpoint
|
305 |
+
3. Update documentation
|
306 |
+
|
307 |
+
### Adding New Features
|
308 |
+
1. Extend appropriate class (`ConversationMemory`, `CharacterPersonality`, etc.)
|
309 |
+
2. Add endpoint if needed
|
310 |
+
3. Update API documentation
|
311 |
+
|
312 |
+
## 📄 License
|
313 |
+
|
314 |
+
MIT License - Lihat file LICENSE untuk detail lengkap.
|
315 |
+
|
316 |
+
## 🙏 Acknowledgments
|
317 |
+
|
318 |
+
- **Hugging Face Transformers** - Model implementation
|
319 |
+
- **FastAPI** - Web framework
|
320 |
+
- **PyTorch** - Deep learning backend
|
321 |
+
- **Community Contributors** - Bug reports and suggestions
|
322 |
+
|
323 |
+
## 📞 Support
|
324 |
+
|
325 |
+
- **Issues**: GitHub Issues
|
326 |
+
- **Discussions**: GitHub Discussions
|
327 |
+
- **Email**: [[email protected]]
|
328 |
+
|
329 |
+
---
|
330 |
+
|
331 |
+
### 📈 Stats
|
332 |
+
- **11 AI Models** supported
|
333 |
+
- **CPU Optimized** for affordable hosting
|
334 |
+
- **Advanced Roleplay** features
|
335 |
+
- **Indonesian Language** optimized
|
336 |
+
- **Real-time Processing** under 500ms average
|
337 |
+
|
338 |
+
**Happy Chatting! 🎭✨**
|