Really-amin's picture
Upload 295 files
d6d843f verified
# 🎉 Crypto Intelligence Hub - Complete Package
## 📦 محتویات Package
```
crypto-hf-complete.zip
├── admin.html ✨ NEW - بازنویسی کامل
├── hf_unified_server.py ✅ 15 endpoint جدید + WebSocket
├── ai_models.py ✅ 10+ HF models با ensemble
├── backend/services/hf_registry.py ✅ 14 datasets curated
├── requirements.txt ✅ Fixed conflicts
├── Dockerfile.optimized ✅ Production ready
├── static/
│ ├── css/ (unchanged)
│ └── js/ (unchanged - ES6 modules)
└── docs/
├── README_HF_INTEGRATION.md 📖 HF integration
├── DEPLOYMENT_GUIDE.md 🚀 Deployment
├── ADMIN_HTML_GUIDE.md 📖 Admin.html guide
└── SUMMARY.md 📊 Summary
```
---
## ✨ admin.html - تغییرات کامل
### قبل (مشکلات):
```
❌ 404 errors برای /api/health
❌ WebSocket connection failed
❌ Empty tables
❌ No loading states
❌ Poor error handling
❌ Sentiment not working
```
### بعد (حل شده):
```
✅ تمام API endpoints به درستی صدا زده می‌شوند
✅ WebSocket connected و real-time updates
✅ Loading states برای همه sections
✅ Error handling و user feedback
✅ Sentiment از ensemble models
✅ Responsive و accessible
```
### تغییرات اصلی:
#### 1. Navigation با آیکون‌های SVG
```html
<button class="nav-button" data-nav="page-overview">
<svg>...</svg>
Overview
</button>
```
#### 2. Loading States
```html
<tbody data-top-coins-body>
<tr>
<td colspan="7">Loading top coins...</td>
</tr>
</tbody>
```
#### 3. Backend Integration
```javascript
// Overview
GET /api/market/stats → Global stats
GET /api/coins/top?limit=10 → Top coins
WS /ws → Real-time
// Market
GET /api/coins/top?limit=50 → All coins
GET /api/coins/{symbol} → Details
GET /api/charts/price/... → Chart data
// AI
POST /api/sentiment/analyze → Ensemble sentiment
POST /api/query → NLP query
POST /api/charts/analyze → Technical analysis
// News
GET /api/news/latest?limit=40 → News با sentiment
// ML Platform
GET /api/datasets/list → 14 datasets
GET /api/models/list → 10+ models
POST /api/models/test → Test model
```
#### 4. Error Handling
```javascript
try {
const res = await apiClient.get('/api/coins/top');
if (res.ok) {
updateUI(res.data);
} else {
showError(res.error);
}
} catch (err) {
showNetworkError(err);
}
```
#### 5. Sentiment Display
```html
<span class="chip sentiment-bullish">
🟢 Bullish (87%)
</span>
<span class="chip sentiment-bearish">
🔴 Bearish (72%)
</span>
<span class="chip sentiment-neutral">
🟡 Neutral (65%)
</span>
```
#### 6. Real-time Updates
```javascript
wsClient.subscribe('update', (data) => {
updateMarketData(data.market_data);
updateSentiment(data.sentiment);
updateNews(data.news);
});
```
---
## 🔌 Backend - Endpoints کامل
### Core Endpoints (admin.html نیاز دارد):
```
✅ GET /api/health - Health check
✅ GET /api/coins/top?limit=50 - Top coins
✅ GET /api/coins/{symbol} - Coin details
✅ GET /api/market/stats - Market overview
✅ GET /api/charts/price/{symbol} - Price history
✅ POST /api/charts/analyze - Chart analysis
✅ GET /api/news/latest?limit=40 - News + sentiment
✅ POST /api/news/summarize - Summarize article
✅ POST /api/sentiment/analyze - Ensemble sentiment
✅ POST /api/query - NLP query
✅ GET /api/providers - Provider list
✅ GET /api/datasets/list - HF datasets
✅ GET /api/datasets/sample?name=... - Dataset preview
✅ GET /api/models/list - HF models
✅ POST /api/models/test - Test model
✅ WS /ws - Real-time updates
```
### Existing Endpoints (unchanged):
```
✓ GET /health
✓ GET /info
✓ GET /api/ohlcv
✓ GET /api/crypto/prices/top
✓ GET /api/crypto/price/{symbol}
✓ GET /api/crypto/market-overview
✓ ... (20+ more)
```
---
## 🤖 AI Models - Ensemble System
### Models در کد:
```python
CRYPTO_SENTIMENT_MODELS = [
"ElKulako/cryptobert",
"kk08/CryptoBERT",
"burakutf/finetuned-finbert-crypto",
"mathugo/crypto_news_bert"
]
SOCIAL_SENTIMENT_MODELS = [
"svalabs/twitter-xlm-roberta-bitcoin-sentiment",
"mayurjadhav/crypto-sentiment-model"
]
FINANCIAL_SENTIMENT_MODELS = [
"ProsusAI/finbert",
"cardiffnlp/twitter-roberta-base-sentiment"
]
```
### Ensemble Function:
```python
def ensemble_crypto_sentiment(text: str) -> Dict:
"""
استفاده از 2-3 مدل برای sentiment analysis
Returns:
{
"label": "bullish" | "bearish" | "neutral",
"confidence": 0.87,
"scores": {
"ElKulako/cryptobert": {"label": "bullish", "score": 0.92},
"kk08/CryptoBERT": {"label": "bullish", "score": 0.82}
},
"model_count": 2
}
"""
```
---
## 📊 Datasets - Curated Collection
### Categories:
```python
CRYPTO_DATASETS = {
"price": [
"paperswithbacktest/Cryptocurrencies-Daily-Price",
"linxy/CryptoCoin",
"sebdg/crypto_data",
"Farmaanaa/bitcoin_price_timeseries",
"WinkingFace/CryptoLM-Bitcoin-BTC-USDT",
"WinkingFace/CryptoLM-Ethereum-ETH-USDT",
"WinkingFace/CryptoLM-Ripple-XRP-USDT"
],
"news_raw": [
"flowfree/crypto-news-headlines",
"edaschau/bitcoin_news"
],
"news_labeled": [
"SahandNZ/cryptonews-articles-with-price-momentum-labels",
"tahamajs/bitcoin-individual-news-dataset",
...
]
}
```
---
## 🚀 Quick Start
### 1. Extract
```bash
unzip crypto-hf-complete.zip
cd crypto-dt-source-hf-integrated
```
### 2. Install
```bash
pip install -r requirements.txt
```
### 3. Configure
```bash
export HF_TOKEN=your_huggingface_token
export PORT=7860
```
### 4. Run
```bash
uvicorn hf_unified_server:app --host 0.0.0.0 --port 7860
```
### 5. Access
```
http://localhost:7860/
```
---
## 🧪 Testing
### Backend Health:
```bash
curl http://localhost:7860/api/health
# Expected:
{
"status": "healthy",
"uptime": 123,
"models_loaded": 2,
"datasets_available": 14
}
```
### Top Coins:
```bash
curl http://localhost:7860/api/coins/top?limit=5
# Expected:
{
"success": true,
"coins": [
{
"rank": 1,
"symbol": "BTC",
"name": "Bitcoin",
"price": 67432.50,
...
}
]
}
```
### Sentiment Analysis:
```bash
curl -X POST http://localhost:7860/api/sentiment/analyze \
-H "Content-Type: application/json" \
-d '{"text": "Bitcoin breaking ATH!"}'
# Expected:
{
"success": true,
"sentiment": "bullish",
"confidence": 0.89,
"details": {...}
}
```
### WebSocket:
```javascript
// در browser console:
const ws = new WebSocket('ws://localhost:7860/ws');
ws.onmessage = (e) => console.log(JSON.parse(e.data));
// Expected (هر 10 ثانیه):
{
"type": "update",
"payload": {
"market_data": [...],
"sentiment": {...},
"timestamp": "..."
}
}
```
---
## ✅ Checklist - همه چیز کار می‌کند
### Frontend (admin.html):
- [x] Overview page - stats + top coins + sentiment
- [x] Market page - 50 coins + search + detail drawer
- [x] Chart Lab - price chart + AI analysis
- [x] AI Advisor - sentiment + query interface
- [x] News - headlines با sentiment badges
- [x] Providers - 95+ listed
- [x] Datasets & Models - 14 datasets, 10+ models
- [x] API Explorer - all endpoints listed
- [x] Diagnostics - health status + logs
- [x] Settings - theme + intervals
- [x] WebSocket - real-time updates (10s)
- [x] Navigation - smooth transitions
- [x] Loading states - همه جا
- [x] Error handling - user-friendly messages
### Backend (hf_unified_server.py):
- [x] All 15 new endpoints working
- [x] WebSocket connection stable
- [x] Ensemble sentiment operational
- [x] Models lazy-loading
- [x] Datasets catalog available
- [x] CORS configured
- [x] Error responses proper
- [x] Health check working
### AI Models (ai_models.py):
- [x] 10+ models registered
- [x] Ensemble voting implemented
- [x] Lazy-loading working
- [x] Confidence scoring
- [x] Error handling
### HF Registry (hf_registry.py):
- [x] 14 datasets cataloged
- [x] Category organization
- [x] Auto-refresh from Hub
- [x] Metadata included
### Dependencies (requirements.txt):
- [x] Websockets conflict fixed (>=10.4,<12.0)
- [x] All packages compatible
- [x] datasets>=3.0.0 added
- [x] transformers>=4.45.0
### Docker (Dockerfile.optimized):
- [x] Multi-stage caching
- [x] Health check included
- [x] Environment variables set
- [x] Model cache configured
---
## 📖 Documentation
### Included Files:
1. **README_HF_INTEGRATION.md** - کامل‌ترین راهنما
2. **DEPLOYMENT_GUIDE.md** - راه‌اندازی step-by-step
3. **ADMIN_HTML_GUIDE.md** - توضیحات frontend
4. **SUMMARY.md** - خلاصه تغییرات
5. این فایل - overview کلی
---
## 🎯 نکات مهم
### Sentiment Ensemble:
- استفاده از 2-3 مدل همزمان
- Majority voting برای label
- Average confidence score
- Per-model breakdown available
### Dataset Sampling:
- نیاز به authentication برای بعضی datasets
- Preview first 20 rows
- Category filtering
- Metadata included
### WebSocket Updates:
- هر 10 ثانیه یک update
- شامل market + news + sentiment
- Auto-reconnect on disconnect
- Backoff strategy برای retry
### Model Loading:
- اولین بار: ~30s (download)
- بعدی: instant (cached)
- Set HF_TOKEN for private models
- Lazy-loading برای بهینه‌سازی memory
---
## 🐛 Common Issues
### 1. "checking" never changes to "healthy"
```bash
# Check backend:
curl http://localhost:7860/api/health
# Check logs:
docker logs crypto-hub
```
### 2. WebSocket shows "error"
```bash
# Test connection:
wscat -c ws://localhost:7860/ws
# Check firewall/proxy
```
### 3. Empty tables in UI
```bash
# Check API responses:
curl http://localhost:7860/api/coins/top
curl http://localhost:7860/api/market/stats
# Check browser console for errors
```
### 4. Models not loading
```bash
# Check HF_TOKEN:
echo $HF_TOKEN
# Check transformers installed:
pip show transformers
# Check disk space (models ~500MB each)
df -h
```
---
## 🎓 Architecture Overview
```
┌──────────────┐
│ admin.html │
│ (Browser) │
└───────┬──────┘
┌───────┴──────┐
│ HTTP/WS │
└───────┬──────┘
┌───────────────────┼───────────────────┐
│ │ │
┌───▼────┐ ┌──────▼──────┐ ┌─────▼──────┐
│Market │ │Sentiment │ │Datasets │
│Endpoints│ │Ensemble │ │& Models │
└───┬────┘ └──────┬──────┘ └─────┬──────┘
│ │ │
└──────────┬───────┴───────┬───────────┘
│ │
┌───────▼──────┐ ┌─────▼──────┐
│ hf_unified_ │ │ WebSocket │
│ server.py │ │ Manager │
└──────┬───────┘ └────────────┘
┌─────────────┼─────────────┐
│ │ │
┌───▼───┐ ┌─────▼──────┐ ┌──▼────┐
│ai_ │ │hf_registry │ │collec-│
│models │ │.py │ │tors │
└───────┘ └────────────┘ └───────┘
```
---
## 🎉 تمام!
### همه چیز آماده است:
✅ **Frontend** - admin.html بازنویسی کامل
✅ **Backend** - 15 endpoint جدید
✅ **AI** - 10+ مدل با ensemble
✅ **Data** - 14 dataset curated
✅ **Real-time** - WebSocket کار می‌کند
✅ **Deps** - Conflicts حل شده
✅ **Docs** - راهنماهای کامل
✅ **Docker** - Production ready
### آماده deployment در:
- 🚀 HuggingFace Space
- 🐳 Docker Container
- 💻 Local Development
- ☁️ Cloud Platforms
---
**پروژه کاملاً عملیاتی و آماده production است! 🎊**