rishithayanidhi/datacenter-cooling-optimization
0
1#2# validate-submission.ps1 — OpenEnv Submission Validator (Windows PowerShell)3#4# Checks that your HF Space is live, Docker image builds, and inference script passes.5#6# Prerequisites:7# - Docker: https://docs.docker.com/get-docker/8# - Python: With openai, asyncio, etc. installed9# - curl (via Invoke-WebRequest)10#11# Run:12# .\validate-submission.ps1 -PingUrl "https://your-space.hf.space"13# .\validate-submission.ps1 -PingUrl "https://your-space.hf.space" -RepoDir ".\my-repo"14#15# Arguments:16# -PingUrl Your HuggingFace Space URL (e.g. https://your-space.hf.space)17# -RepoDir Path to your repo (default: current directory)18#19 20param(21 [Parameter(Mandatory=$true)]22 [string]$PingUrl,23 24 [Parameter(Mandatory=$false)]25 [string]$RepoDir = "."26)27 28$ErrorActionPreference = "Stop"29 30# Color helpers31$code_esc = [char]2732$RESET = "${code_esc}[0m"33$GREEN = "${code_esc}[32m"34$RED = "${code_esc}[31m"35$YELLOW = "${code_esc}[33m"36$BOLD = "${code_esc}[1m"37 38$PASS = 039$FAIL = 040 41function Log {42 param([string]$Message)43 $timestamp = Get-Date -Format "HH:mm:ss"44 Write-Host "[$timestamp] $Message"45}46 47function Pass {48 param([string]$Message)49 Log "$GREEN[PASSED]$RESET -- $Message"50 $script:PASS++51}52 53function Fail {54 param([string]$Message)55 Log "$RED[FAILED]$RESET -- $Message"56 $script:FAIL++57}58 59function Hint {60 param([string]$Message)61 Write-Host " $YELLOW[Hint]$RESET $Message"62}63 64function StopAt {65 param([string]$Step)66 Write-Host ""67 Write-Host "$RED$BOLD❌ Validation stopped at $Step.$RESET"68 Write-Host "Fix the above before continuing."69 exit 170}71 72# Validate repo directory exists73try {74 $RepoDir = (Resolve-Path $RepoDir -ErrorAction Stop).Path75}76catch {77 Write-Host "Error: directory '$RepoDir' not found"78 exit 179}80 81# Normalize URL (remove trailing slash)82$PingUrl = $PingUrl.TrimEnd('/')83 84Write-Host ""85Write-Host "========================================"86Write-Host " OpenEnv Submission Validator"87Write-Host "========================================"88Log "Repo: $RepoDir"89Log "Ping URL: $PingUrl"90Write-Host ""91 92# ============================================================================93# STEP 1: Ping HF Space94# ============================================================================95Log "[Step 1/3] Pinging HF Space ($PingUrl/reset) ..."96 97try {98 $response = Invoke-WebRequest `99 -Uri "$PingUrl/reset" `100 -Method POST `101 -Headers @{"Content-Type" = "application/json"} `102 -Body '{}' `103 -UseBasicParsing `104 -TimeoutSec 30 `105 -ErrorAction Stop106 107 if ($response.StatusCode -eq 200) {108 Pass "HF Space is live and responds to /reset (HTTP 200)"109 }110 else {111 Fail "HF Space /reset returned HTTP $($response.StatusCode) (expected 200)"112 Hint "Make sure your Space is running and the URL is correct."113 StopAt "Step 1"114 }115}116catch {117 Fail "HF Space not reachable (connection failed)"118 Hint "Check your network connection and that the Space is running."119 Hint "Try opening $PingUrl in your browser first."120 Hint "Error: $($_.Exception.Message)"121 StopAt "Step 1"122}123 124# ============================================================================125# STEP 2: Docker Build126# ============================================================================127Log "$BOLD[Step 2/3] Running docker build$RESET ..."128 129# Find Dockerfile130$DockerfilePath = $null131$DockerContext = $null132 133if (Test-Path "$RepoDir/Dockerfile") {134 $DockerfilePath = "$RepoDir/Dockerfile"135 $DockerContext = $RepoDir136}137elseif (Test-Path "$RepoDir/my_env/server/Dockerfile") {138 $DockerfilePath = "$RepoDir/my_env/server/Dockerfile"139 $DockerContext = "$RepoDir/my_env/server"140}141 142if ($null -eq $DockerfilePath) {143 Fail "No Dockerfile found in repo root or my_env/server/ directory"144 StopAt "Step 2"145}146 147Log " Found Dockerfile in $DockerContext"148 149# Check if docker is installed150if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {151 Fail "docker command not found"152 Hint "Install Docker: https://docs.docker.com/get-docker/"153 StopAt "Step 2"154}155 156# Run docker build with timeout157$buildCmd = "docker build `"$DockerContext`""158try {159 $buildOutput = & cmd /c "$buildCmd 2>&1" | Tee-Object -Variable buildLog160 Pass "Docker build succeeded"161}162catch {163 Fail "Docker build failed"164 Hint "Check the Dockerfile for syntax errors"165 Hint "Last 10 lines of build output:"166 if ($buildLog) { $buildLog | Select-Object -Last 10 | ForEach-Object { Write-Host " $_" }}167 StopAt "Step 2"168}169 170# ============================================================================171# STEP 3: Inference Script Validation172# ============================================================================173Log "$BOLD[Step 3/3] Running inference script validation$RESET ..."174 175$inferenceScript = "$RepoDir/inference.py"176if (-not (Test-Path $inferenceScript)) {177 Fail "inference.py not found in repo root"178 Hint "Create $RepoDir/inference.py with proper OpenAI integration"179 StopAt "Step 3"180}181 182# Check required components in inference.py183$validationChecks = @{184 "OpenAI import" = "from openai import|import OpenAI"185 "[START] logging" = "\[START\]"186 "[STEP] logging" = "\[STEP\]"187 "[END] logging" = "\[END\]"188 "Score field" = "score="189 "Environment variables" = "API_BASE_URL|MODEL_NAME|HF_TOKEN"190 "Async support" = "async def|asyncio.run"191}192 193$allChecksPass = $true194foreach ($check in $validationChecks.GetEnumerator()) {195 $content = Get-Content $inferenceScript -Raw196 if ($content -match $check.Value) {197 Log " ✓ $($check.Name) found"198 }199 else {200 Fail " ✗ $($check.Name) not found"201 Hint "Update inference.py to include: $($check.Value)"202 $allChecksPass = $false203 }204}205 206if ($allChecksPass) {207 Pass "inference.py validation passed"208}209else {210 StopAt "Step 3"211}212 213# ============================================================================214# Final Summary215# ============================================================================216Write-Host ""217Write-Host "$BOLD========================================$RESET"218Write-Host "$GREEN$BOLD✅ All 3/3 checks passed!$RESET"219Write-Host "$GREEN$BOLD Your submission is ready to submit.$RESET"220Write-Host "$BOLD========================================$RESET"221Write-Host ""222 223exit 0224 