Spaces:
Paused
Paused
Introduce AI medical extraction service with new API, agents, comprehensive testing, and documentation, while reorganizing existing scripts.
d7f1bb5 | # 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 "" | |