Spaces:
Running on Zero
Running on Zero
Download run_examples.py from infinitylogesh/tempora-1: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/spaces/infinitylogesh/tempora-1/resolve/main/run_examples.py
- Command line
-
hf download hf://spaces/infinitylogesh/tempora-1/run_examples.py
-
curl -L -o run_examples.py https://huggingface.co/spaces/infinitylogesh/tempora-1/resolve/main/run_examples.py
1.96 kB
| """Run example clips through the live Space (release config, thinking on) and save outputs for build_examples.py. | |
| python3 app/space/run_examples.py galaxea_047 steps ... (needs HF_TOKEN with access to the private Space) | |
| """ | |
| import json | |
| import os | |
| import sys | |
| import time | |
| from gradio_client import Client | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| SPACE = os.environ.get("TEMPORA_SPACE", "infinitylogesh/tempora-1") | |
| EXAMPLES = {e["id"]: e for e in json.load(open(os.path.join(HERE, "static", "examples.json")))} | |
| def run(client, ex_id, thinking=True): | |
| ex = EXAMPLES[ex_id] | |
| t0, last = time.time(), None | |
| job = client.submit(video=None, example=ex_id, instruction=ex["instruction"], task=ex["task"], | |
| fields=json.dumps(ex["fields"]), thinking=thinking, api_name="/segment") | |
| for out in job: | |
| d = json.loads(out) | |
| if d["stage"] != last: | |
| print(f" {ex_id} [{time.time() - t0:5.0f}s] {d['stage']}" | |
| + (f" frames={d.get('frames')} input_tokens={d.get('input_tokens')}" if d["stage"] == "queued" else ""), | |
| flush=True) | |
| last = d["stage"] | |
| d = json.loads(job.outputs()[-1]) | |
| assert d["stage"] == "done", d | |
| assert d["prompt"] == ex["prompt"], "the Space built a different prompt than the example's" | |
| return d | |
| def main(): | |
| client = Client(SPACE, token=os.environ["HF_TOKEN"], verbose=False) | |
| os.makedirs(os.path.join(HERE, "example_outputs"), exist_ok=True) | |
| for ex_id in sys.argv[1:]: | |
| d = run(client, ex_id) | |
| st = d.get("stats", {}) | |
| print(f"{ex_id}: {len(d['chunks'] or [])} chunks, {st.get('output_tokens')} output tokens, " | |
| f"{st.get('generate_s')} s generating, {st.get('seconds')} s total, truncated={d.get('truncated')}") | |
| json.dump(d, open(os.path.join(HERE, "example_outputs", f"{ex_id}.json"), "w"), indent=1, ensure_ascii=False) | |
| if __name__ == "__main__": | |
| main() | |