-
Notifications
You must be signed in to change notification settings - Fork 18
/
example.py
68 lines (50 loc) · 1.9 KB
/
example.py
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
# Copyright 2020 by Patrik Jonell.
# All rights reserved.
# This file is part of the GENEA visualizer,
# and is released under the GPLv3 License. Please see the LICENSE
# file that should have been included as part of this package.
import requests
from pathlib import Path
import time
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("bvh_file", type=Path)
parser.add_argument("--server_url", default="http://localhost:5001")
parser.add_argument("--output", type=Path)
args = parser.parse_args()
server_url = args.server_url
bvh_file = args.bvh_file
output = args.output if args.output else bvh_file.with_suffix(".mp4")
headers = {"Authorization": "Bearer j7HgTkwt24yKWfHPpFG3eoydJK6syAsz"}
render_request = requests.post(
f"{server_url}/render",
files={"file": (bvh_file.name, bvh_file.open())},
headers=headers,
)
job_uri = render_request.text
done = False
while not done:
resp = requests.get(server_url + job_uri, headers=headers)
resp.raise_for_status()
response = resp.json()
if response["state"] == "PENDING":
jobs_in_queue = response["result"]["jobs_in_queue"]
print(f"pending.. {jobs_in_queue} jobs currently in queue")
elif response["state"] == "PROCESSING":
print("Processing the file (this can take a while depending on file size)")
elif response["state"] == "RENDERING":
current = response["result"]["current"]
total = response["result"]["total"]
print(f"currently rendering, {current}/{total} done")
elif response["state"] == "SUCCESS":
file_url = response["result"]
done = True
break
elif response["state"] == "FAILURE":
raise Exception(response["result"])
else:
print(response)
raise Exception("should not happen..")
time.sleep(10)
video = requests.get(server_url + file_url, headers=headers).content
output.write_bytes(video)