-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·56 lines (47 loc) · 1.57 KB
/
test.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
#!/usr/bin/env python3
import shutil
import time
import httpx
API_BASE_URL = 'http://localhost:8000'
models = httpx.get(f'{API_BASE_URL}/models/').json()
try:
model = next(filter(lambda x: x['name'] == 'mnist', models))
except StopIteration:
print('Creating model')
shutil.make_archive('examples/mnist', 'zip', 'examples/mnist')
with open('examples/mnist.zip', 'rb') as file:
model = httpx.post(
'http://localhost:8000/models/?name=mnist',
files={'file': file},
).json()
print('Creating jobs')
files = [
'examples/3.png',
'examples/what.png',
]
job_ids = []
for file in files:
with open(file, 'rb') as f:
res = httpx.post('http://localhost:8000/files/', files={
'file': f,
})
uploaded_path = res.json()['path']
res = httpx.post('http://localhost:8000/jobs/', json={
'model_id': model['id'],
'argument_path': uploaded_path,
})
job_id = res.json()['id']
job_ids.append(job_id)
for job_id in job_ids:
status = httpx.get(f'http://localhost:8000/jobs/{job_id}').json()
while status['status'] not in ['completed', 'failed']:
print(f'Job {job_id} is {status["status"]}')
time.sleep(1)
status = httpx.get(f'http://localhost:8000/jobs/{job_id}').json()
if status['status'] == 'failed':
print(f'Job {job_id} failed')
print(status['failed_log'])
else:
result_path = status['result_path']
res = httpx.get(f'http://localhost:8000/files/{result_path}')
print(res.text)