forked from midas-research/audino
-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload_data.py
82 lines (71 loc) · 2.11 KB
/
upload_data.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import argparse
import os
import sys
import requests
import json
from pathlib import Path
parser = argparse.ArgumentParser(description="Upload sample data to project")
parser.add_argument(
"--username",
type=str,
help="Username to which this data will be assigned for annotation",
required=True,
)
parser.add_argument(
"--audio_file",
type=str,
help="Path to audio file which is to be annotated (wav, mp3, ogg only)",
default=False,
)
parser.add_argument(
"--reference_transcription",
type=str,
help="Reference transcription associated with the data",
default=None,
)
parser.add_argument("--host", type=str, help="Host of service", default=None)
parser.add_argument(
"--is_marked_for_review",
type=bool,
help="Whether datapoint should be marked for review",
default=False,
)
parser.add_argument(
"--segmentations",
type=str,
help="List of segmentations for the audio",
default=[],
)
parser.add_argument("--port", type=int, help="Port to make request to", default=80)
args = parser.parse_args()
api_key = os.getenv("API_KEY", None)
headers = {"Authorization": api_key}
audio_path = Path(args.audio_file)
audio_filename = audio_path.name
if audio_path.is_file():
audio_obj = open(audio_path.resolve(), "rb")
else:
print("Audio file does not exist")
exit()
reference_transcription = args.reference_transcription
username = args.username
is_marked_for_review = args.is_marked_for_review
segmentations = args.segmentations
file = {"audio_file": (audio_filename, audio_obj)}
values = {
"reference_transcription": reference_transcription,
"username": username,
"segmentations": segmentations,
"is_marked_for_review": is_marked_for_review,
}
print("Creating datapoint")
response = requests.post(
f"http://{args.host}:{args.port}/api/data", files=file, data=values, headers=headers
)
if response.status_code == 201:
response_json = response.json()
print(f"Message: {response_json['message']}")
else:
print(f"Error Code: {response.status_code}")
response_json = response.json()
print(f"Message: {response_json['message']}")