Spaces:
Paused
Paused
File size: 4,606 Bytes
1cf6b33 | 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 | # Test script for HF Spaces deployment
# Usage: .\test_hf_space.ps1 -SpaceURL "https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE"
param(
[Parameter(Mandatory=$true)]
[string]$SpaceURL,
[Parameter(Mandatory=$false)]
[string]$PatientID = "5247",
[Parameter(Mandatory=$false)]
[string]$Token = "test-token",
[Parameter(Mandatory=$false)]
[string]$Key = "test-key"
)
Write-Host "π§ͺ Testing HF Space Deployment" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Cyan
Write-Host ""
# Remove trailing slash if present
$SpaceURL = $SpaceURL.TrimEnd('/')
# Test 1: Health Check
Write-Host "Test 1: Health Check..." -ForegroundColor Yellow
try {
$healthResponse = Invoke-RestMethod -Uri "$SpaceURL/health" -Method Get -TimeoutSec 10
Write-Host "β
Health check passed" -ForegroundColor Green
Write-Host " Status: $($healthResponse.status)" -ForegroundColor Gray
} catch {
Write-Host "β Health check failed: $_" -ForegroundColor Red
Write-Host " Make sure your Space is running and accessible" -ForegroundColor Yellow
exit 1
}
Write-Host ""
# Test 2: Ready Check
Write-Host "Test 2: Ready Check..." -ForegroundColor Yellow
try {
$readyResponse = Invoke-RestMethod -Uri "$SpaceURL/health/ready" -Method Get -TimeoutSec 10
Write-Host "β
Ready check passed" -ForegroundColor Green
} catch {
Write-Host "β οΈ Ready check failed (Space may still be initializing)" -ForegroundColor Yellow
}
Write-Host ""
# Test 3: Model Status (if endpoint exists)
Write-Host "Test 3: Model Status (optional)..." -ForegroundColor Yellow
try {
$modelStatus = Invoke-RestMethod -Uri "$SpaceURL/api/model-status" -Method Get -TimeoutSec 15
Write-Host "β
Model status retrieved" -ForegroundColor Green
Write-Host " Model loaded: $($modelStatus.model_loaded)" -ForegroundColor Gray
} catch {
Write-Host "β οΈ Model status endpoint not available (this is normal)" -ForegroundColor Yellow
}
Write-Host ""
# Test 4: Summary Generation with Small Model
Write-Host "Test 4: Summary Generation (Small Model)..." -ForegroundColor Yellow
Write-Host " Using: sshleifer/distilbart-cnn-6-6" -ForegroundColor Gray
Write-Host " This may take 1-2 minutes on first request..." -ForegroundColor Gray
$requestBody = @{
patientid = $PatientID
token = $Token
key = $Key
patient_summarizer_model_name = "sshleifer/distilbart-cnn-6-6"
patient_summarizer_model_type = "summarization"
} | ConvertTo-Json
try {
$startTime = Get-Date
$summaryResponse = Invoke-RestMethod -Uri "$SpaceURL/generate_patient_summary" `
-Method Post `
-Body $requestBody `
-ContentType "application/json" `
-TimeoutSec 180
$endTime = Get-Date
$duration = ($endTime - $startTime).TotalSeconds
Write-Host "β
Summary generated successfully!" -ForegroundColor Green
Write-Host " Duration: $([math]::Round($duration, 1)) seconds" -ForegroundColor Gray
Write-Host " Status: $($summaryResponse.status)" -ForegroundColor Gray
if ($summaryResponse.summary -like "*Fallback Mode*") {
Write-Host "β οΈ Warning: Using fallback mode (model didn't load)" -ForegroundColor Yellow
Write-Host " Check logs for model loading errors" -ForegroundColor Yellow
} else {
Write-Host "β
Model loaded and generated summary successfully!" -ForegroundColor Green
}
} catch {
Write-Host "β Summary generation failed" -ForegroundColor Red
Write-Host " Error: $_" -ForegroundColor Red
if ($_.Exception.Response) {
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
$responseBody = $reader.ReadToEnd()
Write-Host " Response: $responseBody" -ForegroundColor Red
}
}
Write-Host ""
Write-Host "================================" -ForegroundColor Cyan
Write-Host "Tests Complete!" -ForegroundColor Cyan
Write-Host ""
Write-Host "π Summary:" -ForegroundColor Yellow
Write-Host " Space URL: $SpaceURL" -ForegroundColor Gray
Write-Host " Patient ID: $PatientID" -ForegroundColor Gray
Write-Host ""
Write-Host "π‘ Next Steps:" -ForegroundColor Yellow
Write-Host " 1. If tests passed, your Space is working!" -ForegroundColor Gray
Write-Host " 2. If summary used fallback mode, check Space logs" -ForegroundColor Gray
Write-Host " 3. Consider enabling preloading for faster responses" -ForegroundColor Gray
Write-Host " 4. See HF_SPACES_MODEL_LOADING_FIX.md for details" -ForegroundColor Gray
Write-Host ""
|