Spaces:
Running
Running
File size: 3,449 Bytes
29ce591 | 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 | import os
import sys
import json
import yaml # PyYAML is needed, usually in these environments
from pathlib import Path
def validate():
cwd = Path.cwd()
errors = []
warnings = []
print(f"π Validating OpenEnv Submission at {cwd}\n")
# 1. README.md Meta Check
readme_path = cwd / "README.md"
if not readme_path.exists():
errors.append("β Missing README.md")
else:
content = readme_path.read_text(encoding="utf-8")
if "---" not in content or "sdk: docker" not in content:
errors.append("β README.md's YAML frontmatter is missing or incorrect (needs 'sdk: docker')")
else:
print("β
README.md metadata found.")
# 2. openenv.yaml Check
openenv_path = cwd / "openenv.yaml"
if not openenv_path.exists():
errors.append("β Missing openenv.yaml")
else:
try:
with open(openenv_path, "r") as f:
cfg = yaml.safe_load(f)
required_keys = ["name", "version", "tasks", "action_space", "observation_space", "deploy"]
for k in required_keys:
if k not in cfg:
errors.append(f"β openenv.yaml is missing required key: {k}")
if len(cfg.get("tasks", [])) < 3:
warnings.append("β οΈ OpenEnv recommends at least 3 tasks (easy, medium, hard).")
print("β
openenv.yaml follows spec.")
except Exception as e:
errors.append(f"β Failed to parse openenv.yaml: {e}")
# 3. Dockerfile Check
docker_path = cwd / "Dockerfile"
if not docker_path.exists():
errors.append("β Missing Dockerfile (Mandatory for HF Space docker SDK)")
else:
print("β
Dockerfile exists.")
# 4. inference.py Check
inference_path = cwd / "inference.py"
if not inference_path.exists():
errors.append("β Missing inference.py in root directory.")
else:
content = inference_path.read_text(encoding="utf-8")
# Mandatory logs check
for tag in ["[START]", "[STEP]", "[END]"]:
if tag not in content:
errors.append(f"β Structured logging tag '{tag}' not found in inference.py")
# Mandatory variables check
for var in ["API_BASE_URL", "MODEL_NAME", "HF_TOKEN"]:
if var not in content:
errors.append(f"β Mandatory variable/env check for '{var}' not found in inference.py")
# OpenAI client check
if "OpenAI" not in content or "client.chat.completions.create" not in content:
errors.append("β inference.py must use OpenAI client for LLM calls.")
print("β
inference.py follows mandatory rules.")
# 5. Requirement Check
req_path = cwd / "requirements.txt"
if not req_path.exists():
errors.append("β Missing requirements.txt")
else:
print("β
requirements.txt exists.")
# Result Summary
print("\n--- Validation Summary ---")
if errors:
for e in errors:
print(e)
print("\nβ FAILED: Please fix errors before submitting.")
sys.exit(1)
else:
if warnings:
for w in warnings:
print(w)
print("\nβ
PASSED: Project matches Scalar Hackathon OpenEnv requirements.")
print("π Ready for submission!")
if __name__ == "__main__":
validate()
|