File size: 920 Bytes
d1f3f31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import pathlib
import time
import sys

def main():
    p = pathlib.Path('audio/conv_001.wav')
    print('exists', p.exists(), 'path', p)
    if not p.exists():
        print('audio file missing', p)
        sys.exit(2)

    with p.open('rb') as f:
        r = requests.post('http://localhost:8000/api/upload', files={'audio': (p.name, f, 'audio/wav')}, timeout=60)
    print('upload', r.status_code)
    print(r.text)
    data = r.json() if r.status_code == 200 else {}
    job_id = data.get('job_id')
    print('job_id', job_id)
    if not job_id:
        sys.exit(3)

    for i in range(20):
        time.sleep(3)
        resp = requests.get(f'http://localhost:8000/api/jobs/{job_id}', timeout=30)
        print('poll', i, resp.status_code, resp.text)
        if resp.status_code == 200 and resp.json().get('status') in ('completed', 'failed'):
            break

if __name__ == '__main__':
    main()