Spaces:
Running on Zero
Running on Zero
File size: 1,960 Bytes
76088f5 e605e7b 76088f5 | 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 | """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()
|