most-client 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- most/__init__.py +1 -0
- most/__pycache__/__init__.cpython-310.pyc +0 -0
- most/__pycache__/api.cpython-310.pyc +0 -0
- most/__pycache__/types.cpython-310.pyc +0 -0
- most/api.py +154 -0
- most/types.py +29 -0
- most_client-1.0.0.dist-info/METADATA +28 -0
- most_client-1.0.0.dist-info/RECORD +11 -0
- most_client-1.0.0.dist-info/WHEEL +5 -0
- most_client-1.0.0.dist-info/top_level.txt +1 -0
- most_client-1.0.0.dist-info/zip-safe +1 -0
most/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
from .api import MostClient
|
Binary file
|
Binary file
|
Binary file
|
most/api.py
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
from typing import List
|
2
|
+
import json5
|
3
|
+
import requests
|
4
|
+
from adaptix import Retort
|
5
|
+
from most.types import Audio, Result
|
6
|
+
from pathlib import Path
|
7
|
+
|
8
|
+
|
9
|
+
class MostClient(object):
|
10
|
+
retort = Retort()
|
11
|
+
|
12
|
+
def __init__(self,
|
13
|
+
client_id=None,
|
14
|
+
client_secret=None,
|
15
|
+
model_id=None):
|
16
|
+
super(MostClient, self).__init__()
|
17
|
+
self.client_id = client_id
|
18
|
+
self.client_secret = client_secret
|
19
|
+
|
20
|
+
if self.client_id is None:
|
21
|
+
credentials = self.load_credentials()
|
22
|
+
self.client_id = credentials.get('client_id')
|
23
|
+
self.client_secret = credentials.get('client_secret')
|
24
|
+
|
25
|
+
if self.client_id is None:
|
26
|
+
print("Visit: https://app.the-most.ai/integrations and get clientId, clientSecret")
|
27
|
+
self.client_id = input("Please enter your client ID: ")
|
28
|
+
self.client_secret = input("Please enter your client secret: ")
|
29
|
+
self.save_credentials()
|
30
|
+
else:
|
31
|
+
self.save_credentials()
|
32
|
+
|
33
|
+
self.session = requests.Session()
|
34
|
+
self.access_token = None
|
35
|
+
self.model_id = model_id
|
36
|
+
|
37
|
+
self.refresh_access_token()
|
38
|
+
|
39
|
+
@property
|
40
|
+
def cache_path(self):
|
41
|
+
path = Path.home() / ".most"
|
42
|
+
path.mkdir(parents=True, exist_ok=True)
|
43
|
+
return path
|
44
|
+
|
45
|
+
def load_credentials(self):
|
46
|
+
path = self.cache_path / "credentials.json"
|
47
|
+
if not path.exists():
|
48
|
+
return {}
|
49
|
+
else:
|
50
|
+
return json5.loads(path.read_text())
|
51
|
+
|
52
|
+
def save_credentials(self):
|
53
|
+
path = self.cache_path / "credentials.json"
|
54
|
+
path.write_text(json5.dumps({
|
55
|
+
"client_id": self.client_id,
|
56
|
+
"client_secret": self.client_secret,
|
57
|
+
}))
|
58
|
+
|
59
|
+
def clone(self):
|
60
|
+
client = MostClient(client_id=self.client_id,
|
61
|
+
client_secret=self.client_secret,
|
62
|
+
model_id=self.model_id)
|
63
|
+
client.access_token = self.access_token
|
64
|
+
client.session = self.session
|
65
|
+
return client
|
66
|
+
|
67
|
+
def with_model(self, model_id):
|
68
|
+
client = self.clone()
|
69
|
+
client.model_id = model_id
|
70
|
+
return client
|
71
|
+
|
72
|
+
def refresh_access_token(self):
|
73
|
+
resp = self.session.post("https://api.the-most.ai/api/external/access_token",
|
74
|
+
json={"client_id": self.client_id,
|
75
|
+
"client_secret": self.client_secret})
|
76
|
+
access_token = resp.json()
|
77
|
+
self.access_token = access_token
|
78
|
+
|
79
|
+
def get(self, url, **kwargs):
|
80
|
+
if self.access_token is None:
|
81
|
+
self.refresh_access_token()
|
82
|
+
headers = kwargs.pop("headers", {})
|
83
|
+
headers.update({"Authorization": "Bearer %s" % self.access_token})
|
84
|
+
resp = self.session.get(url,
|
85
|
+
headers=headers,
|
86
|
+
**kwargs)
|
87
|
+
if resp.status_code == 401:
|
88
|
+
self.refresh_access_token()
|
89
|
+
return self.get(url,
|
90
|
+
headers=headers,
|
91
|
+
**kwargs)
|
92
|
+
return resp
|
93
|
+
|
94
|
+
def post(self, url,
|
95
|
+
data=None,
|
96
|
+
json=None,
|
97
|
+
**kwargs):
|
98
|
+
if self.access_token is None:
|
99
|
+
self.refresh_access_token()
|
100
|
+
headers = kwargs.pop("headers", {})
|
101
|
+
headers.update({"Authorization": "Bearer %s" % self.access_token})
|
102
|
+
resp = self.session.post(url,
|
103
|
+
data=data,
|
104
|
+
json=json,
|
105
|
+
headers=headers,
|
106
|
+
**kwargs)
|
107
|
+
if resp.status_code == 401:
|
108
|
+
self.refresh_access_token()
|
109
|
+
return self.post(url,
|
110
|
+
data=data,
|
111
|
+
json=json,
|
112
|
+
headers=headers,
|
113
|
+
**kwargs)
|
114
|
+
return resp
|
115
|
+
|
116
|
+
def upload_audio(self, audio_path) -> Audio:
|
117
|
+
with open(audio_path, 'rb') as f:
|
118
|
+
resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/upload",
|
119
|
+
files={"audio_file": f})
|
120
|
+
return self.retort.load(resp.json(), Audio)
|
121
|
+
|
122
|
+
def list_audios(self,
|
123
|
+
offset: int = 0,
|
124
|
+
limit: int = 10) -> List[Audio]:
|
125
|
+
resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/list?offset={offset}&limit={limit}")
|
126
|
+
audio_list = resp.json()
|
127
|
+
return self.retort.load(audio_list, List[Audio])
|
128
|
+
|
129
|
+
def list_models(self):
|
130
|
+
resp = self.get("https://api.the-most.ai/api/external/list_models")
|
131
|
+
return [self.with_model(model['model'])
|
132
|
+
for model in resp.json()]
|
133
|
+
|
134
|
+
def apply(self, audio_id) -> Result:
|
135
|
+
resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply")
|
136
|
+
return self.retort.load(resp.json(), Result)
|
137
|
+
|
138
|
+
def apply_later(self, audio_id):
|
139
|
+
raise NotImplementedError()
|
140
|
+
|
141
|
+
def fetch_results(self, audio_id) -> Result:
|
142
|
+
resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/results")
|
143
|
+
return self.retort.load(resp.json(), Result)
|
144
|
+
|
145
|
+
def fetch_text(self, audio_id) -> Result:
|
146
|
+
resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/text")
|
147
|
+
return self.retort.load(resp.json(), Result)
|
148
|
+
|
149
|
+
def __call__(self, audio_path: Path):
|
150
|
+
audio = self.upload_audio(audio_path)
|
151
|
+
return self.apply(audio.id)
|
152
|
+
|
153
|
+
def __repr__(self):
|
154
|
+
return "<MostClient(model_id='%s')>" % (self.model_id, )
|
most/types.py
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
from typing import Optional, List
|
3
|
+
|
4
|
+
|
5
|
+
@dataclass
|
6
|
+
class Audio:
|
7
|
+
id: str
|
8
|
+
url: str
|
9
|
+
|
10
|
+
|
11
|
+
@dataclass
|
12
|
+
class SubcolumnResult:
|
13
|
+
name: str
|
14
|
+
score: Optional[int]
|
15
|
+
description: str
|
16
|
+
|
17
|
+
|
18
|
+
@dataclass
|
19
|
+
class ColumnResult:
|
20
|
+
name: str
|
21
|
+
subcolumns: List[SubcolumnResult]
|
22
|
+
|
23
|
+
|
24
|
+
@dataclass
|
25
|
+
class Result:
|
26
|
+
id: str
|
27
|
+
text: Optional[str]
|
28
|
+
url: Optional[str]
|
29
|
+
results: Optional[List[ColumnResult]]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: most-client
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: Most AI API for https://the-most.ai
|
5
|
+
Home-page: https://github.com/the-most-ai/most-client
|
6
|
+
Author: George Kasparyants
|
7
|
+
Author-email: george@the-most.ai
|
8
|
+
Classifier: Intended Audience :: Developers
|
9
|
+
Classifier: Operating System :: OS Independent
|
10
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
11
|
+
Classifier: Programming Language :: Python
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
13
|
+
Classifier: Programming Language :: Python :: 3.6
|
14
|
+
Requires-Python: >=3.6
|
15
|
+
Requires-Dist: requests
|
16
|
+
Requires-Dist: wheel
|
17
|
+
Requires-Dist: adaptix
|
18
|
+
Requires-Dist: json5
|
19
|
+
Requires-Dist: dataclasses-json
|
20
|
+
Requires-Dist: black
|
21
|
+
Requires-Dist: coverage
|
22
|
+
Requires-Dist: flake8
|
23
|
+
Requires-Dist: mypy
|
24
|
+
Requires-Dist: pylint
|
25
|
+
Requires-Dist: pytest
|
26
|
+
Requires-Dist: tox
|
27
|
+
Requires-Dist: twine
|
28
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
most/__init__.py,sha256=zfyI5dry-rsHP2Rr9YuPPo_fNFUtguZPAt-mbxDQ57I,28
|
2
|
+
most/api.py,sha256=XUkhHtDUmE2aPM4pBtxePiHlYOfkr94Lt_ablddk2pw,5678
|
3
|
+
most/types.py,sha256=DtuMK8TgdjTDXYVtakqEN1ZLH6v1z_LR1jWya9CyCqI,428
|
4
|
+
most/__pycache__/__init__.cpython-310.pyc,sha256=XaR2imVldQ5SeAZZVkYYJ6DxDXnSAdbt5h5VXh8yqB8,142
|
5
|
+
most/__pycache__/api.cpython-310.pyc,sha256=YRvQJLdHA8FseBFvlZnsQtRNB0rV6Gjqz1sQdG9O70E,5292
|
6
|
+
most/__pycache__/types.cpython-310.pyc,sha256=gwNy34k4XAZ8en1VT3S3QbJOoRuqAeUZEBJjgzSEpIg,1131
|
7
|
+
most_client-1.0.0.dist-info/METADATA,sha256=ix_NTtXNoY7ZuFa7sX24txcPkU6xdqnnJogG01W9vtI,843
|
8
|
+
most_client-1.0.0.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
9
|
+
most_client-1.0.0.dist-info/top_level.txt,sha256=2g5fk02LKkM1hV3pVVti_LQ60TToLBcR2zQ3JEKGVk8,5
|
10
|
+
most_client-1.0.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
11
|
+
most_client-1.0.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
most
|
@@ -0,0 +1 @@
|
|
1
|
+
|