Spaces:
Running
Running
Download validator.py from ManojR19/scalarhackatthon: direct link, hf CLI and curl.
- Browser
- Download file 3.45 kB
-
https://huggingface.co/spaces/ManojR19/scalarhackatthon/resolve/main/validator.py
- Command line
-
hf download hf://spaces/ManojR19/scalarhackatthon/validator.py
-
curl -L -o validator.py https://huggingface.co/spaces/ManojR19/scalarhackatthon/resolve/main/validator.py
3.45 kB
| 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() | |