"""Publish the pod's own status and results to the Hub. The control channel of last resort. RunPod's SSH proxy has been dropping roughly two connections in three, corrupting long command lines, and requiring a PTY that echoes everything back -- so every measurement taken through it has been lossy or lost. The Hub has not failed once, and the pod already holds a token for it. push.py status one small JSON, overwritten each tick push.py done status plus the artifacts worth keeping """ import json import os import pathlib import sys import time from huggingface_hub import HfApi REPO = "btsee/oron-tts" api = HfApi(token=os.environ["HF_TOKEN"]) def put(local: pathlib.Path, remote: str, msg: str) -> None: for attempt in range(3): try: api.upload_file(path_or_fileobj=str(local), path_in_repo=remote, repo_id=REPO, commit_message=msg) return except Exception: time.sleep(2 * (attempt + 1)) def main() -> None: mode = sys.argv[1] kept = int(sys.argv[2]) if len(sys.argv) > 2 else 0 running = sys.argv[3] if len(sys.argv) > 3 else "?" started = pathlib.Path("/workspace/.started_at") if not started.is_file(): started.write_text(str(int(time.time()))) elapsed = int(time.time()) - int(started.read_text().strip()) status = {"mode": mode, "kept": kept, "cleaner_running": running, "elapsed_s": elapsed, "kept_per_min": round(kept * 60.0 / elapsed, 2) if elapsed else None, "utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())} p = pathlib.Path("/workspace/status.json") p.write_text(json.dumps(status, indent=2)) put(p, "eval/v4_status.json", f"v4 status: {kept} clips kept") if mode != "done": return # Everything a decision could need, small enough to read from the Hub. for local, remote in ( ("/workspace/bw_summary.json", "eval/v4_bw_summary.json"), ("/workspace/cv/eval_sentences.txt", "eval/v4_cv_eval_sentences.txt"), # write_bundle emits voices.json, not selection.json. ("/workspace/voices_v4/voices.json", "eval/v4_voices.json"), ("/workspace/cv.log", "eval/v4_cv.log"), ): lp = pathlib.Path(local) if lp.is_file(): put(lp, remote, "v4 run artifacts") # The chosen prompts themselves: this is the deliverable. vd = pathlib.Path("/workspace/voices_v4") if vd.is_dir(): for f in sorted(vd.iterdir()): if f.suffix in (".wav", ".txt", ".json"): put(f, f"eval/v4_voices/{f.name}", "v4 candidate reference prompts") # The manifest is the evidence behind the ranking; gzip keeps it small. man = pathlib.Path("/workspace/cv/manifest.jsonl") if man.is_file(): import gzip gz = pathlib.Path("/workspace/manifest_v4.jsonl.gz") gz.write_bytes(gzip.compress(man.read_bytes())) put(gz, "eval/v4_manifest.jsonl.gz", "v4 manifest") if __name__ == "__main__": main()