File size: 7,513 Bytes
deedeab |
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 |
# Admin.html Integration Guide
## ✅ فایل HTML بدون تغییر
فایل `admin.html` شما **کاملاً compatible** با backend جدید است و نیازی به تغییر ندارد چون:
1. ✅ تمام endpoint های مورد نیاز پیاده شده
2. ✅ Response structure ها سازگار هستند
3. ✅ WebSocket support اضافه شده
4. ✅ JavaScript modules با backend sync هستند
## 📁 ساختار فایلها
```
admin.html
└── static/js/
├── app.js # Main app initializer
├── apiClient.js # API wrapper (✅ compatible)
├── wsClient.js # WebSocket client (✅ compatible)
├── overviewView.js # Overview tab
├── marketView.js # Market tab
├── newsView.js # News tab
├── chartLabView.js # Charts tab
├── aiAdvisorView.js # AI Sentiment tab
├── datasetsModelsView.js # Datasets & Models tab
├── apiExplorerView.js # API Explorer tab
├── debugConsoleView.js # Diagnostics tab
├── providersView.js # Providers tab
└── settingsView.js # Settings tab
```
## 🔌 API Endpoints Mapping
### apiClient.js Calls → Backend Endpoints
| Frontend Call | Backend Endpoint | Status |
|--------------|------------------|---------|
| `getHealth()` | `GET /api/health` | ✅ |
| `getTopCoins(limit)` | `GET /api/coins/top?limit={limit}` | ✅ |
| `getCoinDetails(symbol)` | `GET /api/coins/{symbol}` | ✅ |
| `getMarketStats()` | `GET /api/market/stats` | ✅ |
| `getLatestNews(limit)` | `GET /api/news/latest?limit={limit}` | ✅ |
| `getProviders()` | `GET /api/providers` | ✅ |
| `getPriceChart(symbol, timeframe)` | `GET /api/charts/price/{symbol}?timeframe={timeframe}` | ✅ |
| `analyzeChart(payload)` | `POST /api/charts/analyze` | ✅ |
| `runQuery(payload)` | `POST /api/query` | ✅ |
| `analyzeSentiment(payload)` | `POST /api/sentiment/analyze` | ✅ |
| `summarizeNews(item)` | `POST /api/news/summarize` | ✅ |
| `getDatasetsList()` | `GET /api/datasets/list` | ✅ |
| `getDatasetSample(name)` | `GET /api/datasets/sample?name={name}` | ✅ |
| `getModelsList()` | `GET /api/models/list` | ✅ |
| `testModel(payload)` | `POST /api/models/test` | ✅ |
### WebSocket
| Frontend | Backend | Status |
|----------|---------|---------|
| `wsClient.connect()` → `ws://host/ws` | `WS /ws` | ✅ |
| Message format: `{type, payload}` | Same | ✅ |
## 🔄 Response Structure Compatibility
### Example: GET /api/coins/top
**Frontend expects:**
```javascript
{
success: true,
coins: [
{
rank: 1,
symbol: "BTC",
name: "Bitcoin",
price: 45000,
price_change_24h: 2.5,
volume_24h: 25000000000,
market_cap: 850000000000
}
],
count: 10
}
```
**Backend returns:** ✅ Same structure
### Example: GET /api/market/stats
**Frontend expects:**
```javascript
{
success: true,
stats: {
total_market_cap: 1500000000000,
total_volume_24h: 75000000000,
btc_dominance: 45.5,
eth_dominance: 18.2
}
}
```
**Backend returns:** ✅ Same structure
### Example: POST /api/sentiment/analyze
**Frontend sends:**
```javascript
{
text: "Bitcoin is breaking new ATH!"
}
```
**Backend returns:**
```javascript
{
success: true,
sentiment: "bullish",
confidence: 0.89,
details: {
label: "bullish",
confidence: 0.89,
scores: {...},
model_count: 2
}
}
```
✅ Frontend compatible
## 🎨 CSS Files
تمام CSS files موجود هستند:
- ✅ `static/css/design-tokens.css`
- ✅ `static/css/design-system.css`
- ✅ `static/css/dashboard.css`
- ✅ `static/css/pro-dashboard.css`
## 🚀 Deployment
### Step 1: Copy files
```bash
# Admin HTML
cp admin.html /path/to/project/admin.html
# Ensure static files exist
ls static/css/
ls static/js/
```
### Step 2: Start backend
```bash
uvicorn hf_unified_server:app --host 0.0.0.0 --port 7860
```
### Step 3: Access dashboard
```
http://localhost:7860/
# یا
http://localhost:7860/admin.html
```
## ✅ Checklist
### Backend Endpoints
- [x] `/api/health` - Working
- [x] `/api/coins/top` - Returns top coins
- [x] `/api/coins/{symbol}` - Returns coin details
- [x] `/api/market/stats` - Returns market stats
- [x] `/api/news/latest` - Returns news with sentiment
- [x] `/api/charts/price/{symbol}` - Returns price chart
- [x] `/api/charts/analyze` - Returns chart analysis
- [x] `/api/sentiment/analyze` - Ensemble sentiment
- [x] `/api/query` - NLP query
- [x] `/api/providers` - Provider list
- [x] `/api/datasets/list` - Dataset list
- [x] `/api/datasets/sample` - Dataset sample
- [x] `/api/models/list` - Model list
- [x] `/api/models/test` - Model test
- [x] `/ws` - WebSocket real-time
### Frontend Features
- [x] Overview tab - Shows market stats + top coins
- [x] Market tab - Interactive coins table
- [x] Chart Lab - Price charts + AI analysis
- [x] Sentiment & AI - Sentiment analyzer
- [x] News tab - News with sentiment badges
- [x] Providers tab - Provider list
- [x] API Explorer - Endpoint list
- [x] Diagnostics - Health & logs
- [x] Datasets & Models - HF integration
- [x] Settings - Preferences
### WebSocket Features
- [x] Auto-connect on page load
- [x] Real-time market updates (10s interval)
- [x] Connection status indicator
- [x] Auto-reconnect on disconnect
## 🐛 Troubleshooting
### Problem: 404 on endpoints
**Solution:** مطمئن شوید backend running است:
```bash
curl http://localhost:7860/api/health
```
### Problem: WebSocket connection failed
**Solution:** چک کردن CORS و WebSocket config:
```python
# در hf_unified_server.py
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
```
### Problem: Sentiment returns neutral
**Solution:** اولین بار model download میکنه (~30s):
```bash
# Check logs
docker logs crypto-hub
# یا
tail -f logs/app.log
```
### Problem: Dataset sample empty
**Solution:** بعضی datasets نیاز به authentication دارند:
```bash
export HF_TOKEN=your_token
```
## 🎯 Testing
### Quick Test Script
```bash
#!/bin/bash
# Health check
echo "Testing health..."
curl http://localhost:7860/api/health
# Top coins
echo -e "\n\nTesting coins..."
curl http://localhost:7860/api/coins/top?limit=5
# Market stats
echo -e "\n\nTesting market stats..."
curl http://localhost:7860/api/market/stats
# Sentiment
echo -e "\n\nTesting sentiment..."
curl -X POST http://localhost:7860/api/sentiment/analyze \
-H "Content-Type: application/json" \
-d '{"text": "Bitcoin breaking ATH!"}'
# Models
echo -e "\n\nTesting models..."
curl http://localhost:7860/api/models/list
# Datasets
echo -e "\n\nTesting datasets..."
curl http://localhost:7860/api/datasets/list
echo -e "\n\n✅ All tests completed"
```
## 📝 Notes
1. **No changes needed** to admin.html
2. JavaScript modules کاملاً compatible هستند
3. Sentiment از ensemble models استفاده میکند
4. WebSocket هر 10 ثانیه update میفرستد
5. Dataset sampling نیاز به HF_TOKEN دارد
## 🎉 Result
**admin.html بدون هیچ تغییری کار میکند!**
فقط کافیه:
1. Backend رو run کنید
2. admin.html رو باز کنید
3. همه features کار میکنند ✅
---
**تاریخ:** 2025-11-18
**نسخه:** v5.0.0-hf-integrated
**Status:** Production Ready 🚀
|