most-client 1.0.0__py3-none-any.whl → 1.0.2__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/__pycache__/__init__.cpython-310.pyc +0 -0
- most/__pycache__/api.cpython-310.pyc +0 -0
- most/__pycache__/async_api.cpython-310.pyc +0 -0
- most/__pycache__/types.cpython-310.pyc +0 -0
- most/api.py +17 -3
- most/async_api.py +176 -0
- most/types.py +11 -0
- {most_client-1.0.0.dist-info → most_client-1.0.2.dist-info}/METADATA +2 -1
- most_client-1.0.2.dist-info/RECORD +13 -0
- {most_client-1.0.0.dist-info → most_client-1.0.2.dist-info}/WHEEL +1 -1
- most_client-1.0.0.dist-info/RECORD +0 -11
- {most_client-1.0.0.dist-info → most_client-1.0.2.dist-info}/top_level.txt +0 -0
- {most_client-1.0.0.dist-info → most_client-1.0.2.dist-info}/zip-safe +0 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
most/api.py
CHANGED
@@ -2,7 +2,7 @@ from typing import List
|
|
2
2
|
import json5
|
3
3
|
import requests
|
4
4
|
from adaptix import Retort
|
5
|
-
from most.types import Audio, Result
|
5
|
+
from most.types import Audio, Result, Script
|
6
6
|
from pathlib import Path
|
7
7
|
|
8
8
|
|
@@ -126,12 +126,20 @@ class MostClient(object):
|
|
126
126
|
audio_list = resp.json()
|
127
127
|
return self.retort.load(audio_list, List[Audio])
|
128
128
|
|
129
|
+
def get_model_script(self) -> Script:
|
130
|
+
if self.model_id is None:
|
131
|
+
raise RuntimeError("Please choose a model to apply. [try list_models()]")
|
132
|
+
resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/script")
|
133
|
+
return self.retort.load(resp.json(), Script)
|
134
|
+
|
129
135
|
def list_models(self):
|
130
136
|
resp = self.get("https://api.the-most.ai/api/external/list_models")
|
131
137
|
return [self.with_model(model['model'])
|
132
138
|
for model in resp.json()]
|
133
139
|
|
134
140
|
def apply(self, audio_id) -> Result:
|
141
|
+
if self.model_id is None:
|
142
|
+
raise RuntimeError("Please choose a model to apply. [try list_models()]")
|
135
143
|
resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply")
|
136
144
|
return self.retort.load(resp.json(), Result)
|
137
145
|
|
@@ -139,11 +147,17 @@ class MostClient(object):
|
|
139
147
|
raise NotImplementedError()
|
140
148
|
|
141
149
|
def fetch_results(self, audio_id) -> Result:
|
142
|
-
|
150
|
+
if self.model_id is None:
|
151
|
+
raise RuntimeError("Please choose a model to apply. [try list_models()]")
|
152
|
+
|
153
|
+
resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/results")
|
143
154
|
return self.retort.load(resp.json(), Result)
|
144
155
|
|
145
156
|
def fetch_text(self, audio_id) -> Result:
|
146
|
-
|
157
|
+
if self.model_id is None:
|
158
|
+
raise RuntimeError("Please choose a model to apply. [try list_models()]")
|
159
|
+
|
160
|
+
resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/text")
|
147
161
|
return self.retort.load(resp.json(), Result)
|
148
162
|
|
149
163
|
def __call__(self, audio_path: Path):
|
most/async_api.py
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
from typing import List
|
2
|
+
import json5
|
3
|
+
from adaptix import Retort
|
4
|
+
from most.types import Audio, Result, Script
|
5
|
+
from pathlib import Path
|
6
|
+
import httpx
|
7
|
+
|
8
|
+
|
9
|
+
class AsyncMostClient(object):
|
10
|
+
retort = Retort()
|
11
|
+
|
12
|
+
def __init__(self,
|
13
|
+
client_id=None,
|
14
|
+
client_secret=None,
|
15
|
+
model_id=None):
|
16
|
+
super(AsyncMostClient, 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 = httpx.AsyncClient()
|
34
|
+
self.access_token = None
|
35
|
+
self.model_id = model_id
|
36
|
+
|
37
|
+
async def __aenter__(self):
|
38
|
+
await self.session.__aenter__()
|
39
|
+
await self.refresh_access_token()
|
40
|
+
return self
|
41
|
+
|
42
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
43
|
+
await self.session.__aexit__(exc_type, exc_val, exc_tb)
|
44
|
+
|
45
|
+
@property
|
46
|
+
def cache_path(self):
|
47
|
+
path = Path.home() / ".most"
|
48
|
+
path.mkdir(parents=True, exist_ok=True)
|
49
|
+
return path
|
50
|
+
|
51
|
+
def load_credentials(self):
|
52
|
+
path = self.cache_path / "credentials.json"
|
53
|
+
if not path.exists():
|
54
|
+
return {}
|
55
|
+
else:
|
56
|
+
return json5.loads(path.read_text())
|
57
|
+
|
58
|
+
def save_credentials(self):
|
59
|
+
path = self.cache_path / "credentials.json"
|
60
|
+
path.write_text(json5.dumps({
|
61
|
+
"client_id": self.client_id,
|
62
|
+
"client_secret": self.client_secret,
|
63
|
+
}))
|
64
|
+
|
65
|
+
def clone(self):
|
66
|
+
client = AsyncMostClient(client_id=self.client_id,
|
67
|
+
client_secret=self.client_secret,
|
68
|
+
model_id=self.model_id)
|
69
|
+
client.access_token = self.access_token
|
70
|
+
client.session = self.session
|
71
|
+
return client
|
72
|
+
|
73
|
+
def with_model(self, model_id):
|
74
|
+
client = self.clone()
|
75
|
+
client.model_id = model_id
|
76
|
+
return client
|
77
|
+
|
78
|
+
async def refresh_access_token(self):
|
79
|
+
resp = await self.session.post("https://api.the-most.ai/api/external/access_token",
|
80
|
+
json={"client_id": self.client_id,
|
81
|
+
"client_secret": self.client_secret})
|
82
|
+
access_token = resp.json()
|
83
|
+
self.access_token = access_token
|
84
|
+
|
85
|
+
async def get(self, url, **kwargs):
|
86
|
+
if self.access_token is None:
|
87
|
+
await self.refresh_access_token()
|
88
|
+
headers = kwargs.pop("headers", {})
|
89
|
+
headers.update({"Authorization": "Bearer %s" % self.access_token})
|
90
|
+
resp = await self.session.get(url,
|
91
|
+
headers=headers,
|
92
|
+
**kwargs)
|
93
|
+
if resp.status_code == 401:
|
94
|
+
await self.refresh_access_token()
|
95
|
+
return await self.get(url,
|
96
|
+
headers=headers,
|
97
|
+
**kwargs)
|
98
|
+
return resp
|
99
|
+
|
100
|
+
async def post(self, url,
|
101
|
+
data=None,
|
102
|
+
json=None,
|
103
|
+
**kwargs):
|
104
|
+
if self.access_token is None:
|
105
|
+
await self.refresh_access_token()
|
106
|
+
headers = kwargs.pop("headers", {})
|
107
|
+
headers.update({"Authorization": "Bearer %s" % self.access_token})
|
108
|
+
resp = await self.session.post(url,
|
109
|
+
data=data,
|
110
|
+
json=json,
|
111
|
+
headers=headers,
|
112
|
+
**kwargs)
|
113
|
+
if resp.status_code == 401:
|
114
|
+
await self.refresh_access_token()
|
115
|
+
return await self.post(url,
|
116
|
+
data=data,
|
117
|
+
json=json,
|
118
|
+
headers=headers,
|
119
|
+
**kwargs)
|
120
|
+
return resp
|
121
|
+
|
122
|
+
async def upload_audio(self, audio_path) -> Audio:
|
123
|
+
with open(audio_path, mode='rb') as f:
|
124
|
+
resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/upload",
|
125
|
+
files={"audio_file": f},
|
126
|
+
timeout=None)
|
127
|
+
return self.retort.load(resp.json(), Audio)
|
128
|
+
|
129
|
+
async def list_audios(self,
|
130
|
+
offset: int = 0,
|
131
|
+
limit: int = 10) -> List[Audio]:
|
132
|
+
resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/list?offset={offset}&limit={limit}")
|
133
|
+
audio_list = resp.json()
|
134
|
+
return self.retort.load(audio_list, List[Audio])
|
135
|
+
|
136
|
+
async def get_model_script(self) -> Script:
|
137
|
+
if self.model_id is None:
|
138
|
+
raise RuntimeError("Please choose a model to apply. [try list_models()]")
|
139
|
+
resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/script")
|
140
|
+
return self.retort.load(resp.json(), Script)
|
141
|
+
|
142
|
+
async def list_models(self):
|
143
|
+
resp = await self.get("https://api.the-most.ai/api/external/list_models")
|
144
|
+
return [self.with_model(model['model'])
|
145
|
+
for model in resp.json()]
|
146
|
+
|
147
|
+
async def apply(self, audio_id) -> Result:
|
148
|
+
if self.model_id is None:
|
149
|
+
raise RuntimeError("Please choose a model to apply. [try list_models()]")
|
150
|
+
resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply",
|
151
|
+
timeout=None)
|
152
|
+
return self.retort.load(resp.json(), Result)
|
153
|
+
|
154
|
+
async def apply_later(self, audio_id):
|
155
|
+
raise NotImplementedError()
|
156
|
+
|
157
|
+
async def fetch_results(self, audio_id) -> Result:
|
158
|
+
if self.model_id is None:
|
159
|
+
raise RuntimeError("Please choose a model to apply. [try list_models()]")
|
160
|
+
|
161
|
+
resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/results")
|
162
|
+
return self.retort.load(resp.json(), Result)
|
163
|
+
|
164
|
+
async def fetch_text(self, audio_id) -> Result:
|
165
|
+
if self.model_id is None:
|
166
|
+
raise RuntimeError("Please choose a model to apply. [try list_models()]")
|
167
|
+
|
168
|
+
resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/text")
|
169
|
+
return self.retort.load(resp.json(), Result)
|
170
|
+
|
171
|
+
async def __call__(self, audio_path: Path):
|
172
|
+
audio = await self.upload_audio(audio_path)
|
173
|
+
return await self.apply(audio.id)
|
174
|
+
|
175
|
+
def __repr__(self):
|
176
|
+
return "<MostClient(model_id='%s')>" % (self.model_id, )
|
most/types.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: most-client
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.2
|
4
4
|
Summary: Most AI API for https://the-most.ai
|
5
5
|
Home-page: https://github.com/the-most-ai/most-client
|
6
6
|
Author: George Kasparyants
|
@@ -25,4 +25,5 @@ Requires-Dist: pylint
|
|
25
25
|
Requires-Dist: pytest
|
26
26
|
Requires-Dist: tox
|
27
27
|
Requires-Dist: twine
|
28
|
+
Requires-Dist: httpx
|
28
29
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
most/__init__.py,sha256=zfyI5dry-rsHP2Rr9YuPPo_fNFUtguZPAt-mbxDQ57I,28
|
2
|
+
most/api.py,sha256=MRg52eg6Lf_sFwfTy2XYDHiD9VZSQ22BbvvkqQA1Fv0,6373
|
3
|
+
most/async_api.py,sha256=ypdQ1P-aDblDlM6LbxNDjVjrkp-INJvg5an1n0vhi-E,7003
|
4
|
+
most/types.py,sha256=7FgmaE7xHXggoU859BucqB13DA83CqmUPmBEuikNqE8,548
|
5
|
+
most/__pycache__/__init__.cpython-310.pyc,sha256=5RlgyJsgWSNkWEufVPFWDKxat0cEMCdwD8QFz5FvIj8,193
|
6
|
+
most/__pycache__/api.cpython-310.pyc,sha256=vAmUcfJHdL-59JuzcMpDfQedBaTk62nomDuzTt-thx0,5894
|
7
|
+
most/__pycache__/async_api.cpython-310.pyc,sha256=ng8wYkVziihVAMlv1ugFQQf-qFqP0NgAIfqKqE-K4k8,6615
|
8
|
+
most/__pycache__/types.cpython-310.pyc,sha256=OE7jIlp_0lo6XAwsnVnbsYsjjppGzTUcVo5ve6uHnQg,1492
|
9
|
+
most_client-1.0.2.dist-info/METADATA,sha256=7gIy21ifYHR1jPNd-_rxkb-mDHK9pNRt18w7vwlxPto,864
|
10
|
+
most_client-1.0.2.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
|
11
|
+
most_client-1.0.2.dist-info/top_level.txt,sha256=2g5fk02LKkM1hV3pVVti_LQ60TToLBcR2zQ3JEKGVk8,5
|
12
|
+
most_client-1.0.2.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
13
|
+
most_client-1.0.2.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|