File size: 9,454 Bytes
d6d843f |
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 |
#!/bin/bash
# HuggingFace Space Integration Diagnostic Tool
# Version: 2.0
# Usage: bash diagnostic.sh
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Configuration
HF_SPACE_URL="https://really-amin-datasourceforcryptocurrency.hf.space"
RESULTS_FILE="diagnostic_results_$(date +%Y%m%d_%H%M%S).log"
# Counter for tests
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0
# Function to print status
print_status() {
if [ $1 -eq 0 ]; then
echo -e "${GREEN}β
PASS${NC}: $2"
((PASSED_TESTS++))
else
echo -e "${RED}β FAIL${NC}: $2"
((FAILED_TESTS++))
fi
((TOTAL_TESTS++))
}
# Function to print section header
print_header() {
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo -e "${CYAN}$1${NC}"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
}
# Function to test endpoint
test_endpoint() {
local endpoint=$1
local description=$2
local expected_status=${3:-200}
echo -e "\n${BLUE}Testing:${NC} $description"
echo "Endpoint: $endpoint"
response=$(curl -s -w "\n%{http_code}" --connect-timeout 10 "$endpoint" 2>&1)
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
echo "HTTP Status: $http_code"
if [ "$http_code" = "$expected_status" ]; then
print_status 0 "$description"
echo "Response preview:"
echo "$body" | head -n 3
return 0
else
print_status 1 "$description (Expected $expected_status, got $http_code)"
echo "Error details:"
echo "$body" | head -n 2
return 1
fi
}
# Start logging
exec > >(tee -a "$RESULTS_FILE")
exec 2>&1
# Print banner
clear
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β β"
echo "β HuggingFace Space Integration Diagnostic Tool β"
echo "β Version 2.0 β"
echo "β β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo "Starting diagnostic at $(date)"
echo "Results will be saved to: $RESULTS_FILE"
echo ""
# Test 1: System Requirements
print_header "TEST 1: System Requirements"
echo "Checking required tools..."
node --version > /dev/null 2>&1
print_status $? "Node.js installed ($(node --version 2>/dev/null || echo 'N/A'))"
npm --version > /dev/null 2>&1
print_status $? "npm installed ($(npm --version 2>/dev/null || echo 'N/A'))"
curl --version > /dev/null 2>&1
print_status $? "curl installed"
git --version > /dev/null 2>&1
print_status $? "git installed"
command -v jq > /dev/null 2>&1
if [ $? -eq 0 ]; then
print_status 0 "jq installed (JSON processor)"
else
print_status 1 "jq installed (optional but recommended)"
fi
# Test 2: Project Structure
print_header "TEST 2: Project Structure"
[ -f "package.json" ]
print_status $? "package.json exists"
[ -f ".env.example" ]
print_status $? ".env.example exists"
[ -d "hf-data-engine" ]
print_status $? "hf-data-engine directory exists"
[ -f "hf-data-engine/main.py" ]
print_status $? "HuggingFace engine implementation exists"
[ -f "hf-data-engine/requirements.txt" ]
print_status $? "Python requirements.txt exists"
[ -f "HUGGINGFACE_DIAGNOSTIC_GUIDE.md" ]
print_status $? "Diagnostic guide documentation exists"
# Test 3: Environment Configuration
print_header "TEST 3: Environment Configuration"
if [ -f ".env" ]; then
print_status 0 ".env file exists"
grep -q "PRIMARY_DATA_SOURCE" .env
print_status $? "PRIMARY_DATA_SOURCE configured"
grep -q "HF_SPACE_BASE_URL\|HF_SPACE_URL" .env
print_status $? "HuggingFace Space URL configured"
echo ""
echo "Current configuration (sensitive values hidden):"
grep "PRIMARY_DATA_SOURCE\|HF_SPACE\|FALLBACK" .env | sed 's/=.*/=***/' | sort || true
else
print_status 1 ".env file exists"
echo ""
echo "β οΈ .env file not found. Creating from .env.example..."
if [ -f ".env.example" ]; then
cp .env.example .env
echo "β
.env created. Edit it with your configuration."
fi
fi
# Test 4: HuggingFace Space Connectivity
print_header "TEST 4: HuggingFace Space Connectivity"
echo "Resolving DNS..."
host really-amin-datasourceforcryptocurrency.hf.space > /dev/null 2>&1
print_status $? "DNS resolution for HF Space"
echo ""
echo "Testing basic connectivity..."
ping -c 1 -W 5 hf.space > /dev/null 2>&1
print_status $? "Network connectivity to hf.space"
# Test 5: HuggingFace Space Endpoints
print_header "TEST 5: HuggingFace Space Endpoints"
echo "Testing primary endpoints..."
test_endpoint "$HF_SPACE_URL/api/health" "Health check endpoint"
test_endpoint "$HF_SPACE_URL/api/prices?symbols=BTC,ETH" "Prices endpoint"
test_endpoint "$HF_SPACE_URL/api/ohlcv?symbol=BTCUSDT&interval=1h&limit=10" "OHLCV endpoint"
test_endpoint "$HF_SPACE_URL/api/market/overview" "Market overview endpoint"
test_endpoint "$HF_SPACE_URL/api/sentiment" "Sentiment endpoint"
# Test 6: CORS Configuration
print_header "TEST 6: CORS Configuration"
echo "Checking CORS headers..."
cors_response=$(curl -s -I -H "Origin: http://localhost:5173" "$HF_SPACE_URL/api/prices?symbols=BTC" 2>&1)
cors_headers=$(echo "$cors_response" | grep -i "access-control")
if [ -z "$cors_headers" ]; then
print_status 1 "CORS headers present"
echo ""
echo "β οΈ No CORS headers found. This may cause browser errors."
echo " Solution: Use Vite proxy (see Configuration Guide)"
else
print_status 0 "CORS headers present"
echo "CORS headers found:"
echo "$cors_headers" | sed 's/^/ /'
fi
# Test 7: Response Format Validation
print_header "TEST 7: Response Format Validation"
echo "Fetching sample data..."
sample_response=$(curl -s "$HF_SPACE_URL/api/prices?symbols=BTC" 2>&1)
if command -v jq > /dev/null 2>&1; then
if echo "$sample_response" | jq . > /dev/null 2>&1; then
print_status 0 "Valid JSON response"
echo ""
echo "Response structure:"
if echo "$sample_response" | jq 'keys' 2>/dev/null | grep -q "."; then
echo "$sample_response" | jq 'if type == "array" then .[0] else . end | keys' 2>/dev/null | sed 's/^/ /'
else
echo " (Unable to determine structure)"
fi
else
print_status 1 "Valid JSON response"
echo "Response is not valid JSON:"
echo "$sample_response" | head -n 2 | sed 's/^/ /'
fi
else
echo "β οΈ jq not installed, skipping JSON validation"
echo " Install with: sudo apt-get install jq (Ubuntu) or brew install jq (Mac)"
fi
# Test 8: Node Dependencies
print_header "TEST 8: Node Dependencies"
if [ -d "node_modules" ]; then
print_status 0 "node_modules exists"
[ -d "node_modules/typescript" ]
print_status $? "TypeScript installed"
[ -d "node_modules/vite" ]
print_status $? "Vite installed"
[ -d "node_modules/react" ]
print_status $? "React installed"
# Count total packages
package_count=$(ls -1 node_modules 2>/dev/null | grep -v "^\." | wc -l)
echo " Total packages installed: $package_count"
else
print_status 1 "node_modules exists"
echo ""
echo "β οΈ Run: npm install"
fi
# Test 9: Python Dependencies (if backend is present)
print_header "TEST 9: Python Dependencies"
if [ -f "hf-data-engine/requirements.txt" ]; then
print_status 0 "requirements.txt exists"
python3 -c "import fastapi" 2>/dev/null
[ $? -eq 0 ] && fastapi_status="β
" || fastapi_status="β"
echo " FastAPI: $fastapi_status"
python3 -c "import aiohttp" 2>/dev/null
[ $? -eq 0 ] && aiohttp_status="β
" || aiohttp_status="β"
echo " aiohttp: $aiohttp_status"
python3 -c "import pydantic" 2>/dev/null
[ $? -eq 0 ] && pydantic_status="β
" || pydantic_status="β"
echo " pydantic: $pydantic_status"
else
print_status 1 "requirements.txt exists"
fi
# Summary
print_header "DIAGNOSTIC SUMMARY"
total_status=$((PASSED_TESTS + FAILED_TESTS))
if [ $total_status -gt 0 ]; then
pass_rate=$((PASSED_TESTS * 100 / total_status))
echo "Results: ${GREEN}$PASSED_TESTS passed${NC}, ${RED}$FAILED_TESTS failed${NC} (${pass_rate}%)"
fi
echo ""
echo "Results saved to: $RESULTS_FILE"
echo ""
if [ $FAILED_TESTS -eq 0 ]; then
echo -e "${GREEN}β
All tests passed!${NC}"
echo ""
echo "Next steps:"
echo " 1. Run: npm run dev"
echo " 2. Open: http://localhost:5173"
echo " 3. Check browser console (F12) for any errors"
else
echo -e "${YELLOW}β οΈ Some tests failed${NC}"
echo ""
echo "Next steps:"
echo " 1. Review the failed tests above"
echo " 2. Check HUGGINGFACE_DIAGNOSTIC_GUIDE.md for solutions"
echo " 3. Run this script again after fixes"
fi
echo ""
echo "Full diagnostic completed at $(date)"
echo ""
|