most-client 1.0.19__tar.gz → 1.0.20__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: most-client
3
- Version: 1.0.19
3
+ Version: 1.0.20
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
@@ -9,6 +9,7 @@ import requests
9
9
  from adaptix import Retort
10
10
  from pydub import AudioSegment
11
11
 
12
+ from most.score_calculation import ScoreCalculation
12
13
  from most.types import (
13
14
  Audio,
14
15
  DialogResult,
@@ -17,7 +18,7 @@ from most.types import (
17
18
  Script,
18
19
  StoredAudioData,
19
20
  Text,
20
- is_valid_id, SearchParams,
21
+ is_valid_id, SearchParams, ScriptScoreMapping,
21
22
  )
22
23
 
23
24
 
@@ -48,6 +49,7 @@ class MostClient(object):
48
49
  self.session = requests.Session()
49
50
  self.access_token = None
50
51
  self.model_id = model_id
52
+ self.score_modifier = None
51
53
 
52
54
  self.refresh_access_token()
53
55
 
@@ -77,11 +79,13 @@ class MostClient(object):
77
79
  model_id=self.model_id)
78
80
  client.access_token = self.access_token
79
81
  client.session = self.session
82
+ client.score_modifier = self.score_modifier
80
83
  return client
81
84
 
82
85
  def with_model(self, model_id):
83
86
  client = self.clone()
84
87
  client.model_id = model_id
88
+ client.score_modifier = None
85
89
  return client
86
90
 
87
91
  def refresh_access_token(self):
@@ -176,12 +180,23 @@ class MostClient(object):
176
180
  resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/script")
177
181
  return self.retort.load(resp.json(), Script)
178
182
 
183
+ def get_score_modifier(self):
184
+ if self.score_modifier is None:
185
+ if not is_valid_id(self.model_id):
186
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
187
+
188
+ resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/score_mapping")
189
+ score_mapping = self.retort.load(resp.json(), List[ScriptScoreMapping])
190
+ self.score_modifier = ScoreCalculation(score_mapping)
191
+ return self.score_modifier
192
+
179
193
  def list_models(self):
180
194
  resp = self.get("https://api.the-most.ai/api/external/list_models")
181
195
  return [self.with_model(model['model'])
182
196
  for model in resp.json()]
183
197
 
184
- def apply(self, audio_id) -> Result:
198
+ def apply(self, audio_id,
199
+ modify_scores: bool = False) -> Result:
185
200
  if not is_valid_id(self.model_id):
186
201
  raise RuntimeError("Please choose valid model to apply. [try list_models()]")
187
202
 
@@ -189,9 +204,13 @@ class MostClient(object):
189
204
  raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
190
205
 
191
206
  resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply")
192
- return self.retort.load(resp.json(), Result)
207
+ result = self.retort.load(resp.json(), Result)
208
+ if modify_scores:
209
+ result = self.score_modifier.modify(result)
210
+ return result
193
211
 
194
- def apply_later(self, audio_id) -> Result:
212
+ def apply_later(self, audio_id,
213
+ modify_scores: bool = False) -> Result:
195
214
  if not is_valid_id(self.model_id):
196
215
  raise RuntimeError("Please choose valid model to apply. [try list_models()]")
197
216
 
@@ -199,7 +218,10 @@ class MostClient(object):
199
218
  raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
200
219
 
201
220
  resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply_async")
202
- return self.retort.load(resp.json(), Result)
221
+ result = self.retort.load(resp.json(), Result)
222
+ if modify_scores:
223
+ result = self.score_modifier.modify(result)
224
+ return result
203
225
 
204
226
  def get_job_status(self, audio_id) -> JobStatus:
205
227
  if not is_valid_id(self.model_id):
@@ -211,7 +233,8 @@ class MostClient(object):
211
233
  resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply_status")
212
234
  return self.retort.load(resp.json(), JobStatus)
213
235
 
214
- def fetch_results(self, audio_id) -> Result:
236
+ def fetch_results(self, audio_id,
237
+ modify_scores: bool = False) -> Result:
215
238
  if not is_valid_id(self.model_id):
216
239
  raise RuntimeError("Please choose valid model to apply. [try list_models()]")
217
240
 
@@ -219,7 +242,10 @@ class MostClient(object):
219
242
  raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
220
243
 
221
244
  resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/results")
222
- return self.retort.load(resp.json(), Result)
245
+ result = self.retort.load(resp.json(), Result)
246
+ if modify_scores:
247
+ result = self.score_modifier.modify(result)
248
+ return result
223
249
 
224
250
  def fetch_text(self, audio_id: str) -> Result:
225
251
  if not is_valid_id(self.model_id):
@@ -9,6 +9,7 @@ import json5
9
9
  from adaptix import Retort
10
10
  from pydub import AudioSegment
11
11
 
12
+ from most.score_calculation import ScoreCalculation
12
13
  from most.types import (
13
14
  Audio,
14
15
  DialogResult,
@@ -17,7 +18,7 @@ from most.types import (
17
18
  Script,
18
19
  StoredAudioData,
19
20
  Text,
20
- is_valid_id, SearchParams,
21
+ is_valid_id, SearchParams, ScriptScoreMapping,
21
22
  )
22
23
 
23
24
 
@@ -48,6 +49,7 @@ class AsyncMostClient(object):
48
49
  self.session = httpx.AsyncClient()
49
50
  self.access_token = None
50
51
  self.model_id = model_id
52
+ self.score_modifier: Optional[ScoreCalculation] = None
51
53
 
52
54
  async def __aenter__(self):
53
55
  await self.session.__aenter__()
@@ -83,6 +85,7 @@ class AsyncMostClient(object):
83
85
  model_id=self.model_id)
84
86
  client.access_token = self.access_token
85
87
  client.session = self.session
88
+ client.score_modifier = self.score_modifier
86
89
  return client
87
90
 
88
91
  def with_model(self, model_id):
@@ -90,6 +93,7 @@ class AsyncMostClient(object):
90
93
  if not is_valid_id(self.model_id):
91
94
  raise RuntimeError("Please choose valid model to apply. [try list_models()]")
92
95
  client.model_id = model_id
96
+ client.score_modifier = None
93
97
  return client
94
98
 
95
99
  async def refresh_access_token(self):
@@ -185,12 +189,23 @@ class AsyncMostClient(object):
185
189
  resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/script")
186
190
  return self.retort.load(resp.json(), Script)
187
191
 
192
+ async def get_score_modifier(self):
193
+ if self.score_modifier is None:
194
+ if not is_valid_id(self.model_id):
195
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
196
+
197
+ resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/score_mapping")
198
+ score_mapping = self.retort.load(resp.json(), List[ScriptScoreMapping])
199
+ self.score_modifier = ScoreCalculation(score_mapping)
200
+ return self.score_modifier
201
+
188
202
  async def list_models(self):
189
203
  resp = await self.get("https://api.the-most.ai/api/external/list_models")
190
204
  return [self.with_model(model['model'])
191
205
  for model in resp.json()]
192
206
 
193
- async def apply(self, audio_id) -> Result:
207
+ async def apply(self, audio_id,
208
+ modify_scores: bool = False) -> Result:
194
209
  if not is_valid_id(self.model_id):
195
210
  raise RuntimeError("Please choose valid model to apply. [try list_models()]")
196
211
 
@@ -198,9 +213,13 @@ class AsyncMostClient(object):
198
213
  raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
199
214
 
200
215
  resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply")
201
- return self.retort.load(resp.json(), Result)
216
+ result = self.retort.load(resp.json(), Result)
217
+ if modify_scores:
218
+ result = self.score_modifier.modify(result)
219
+ return result
202
220
 
203
- async def apply_later(self, audio_id):
221
+ async def apply_later(self, audio_id,
222
+ modify_scores: bool = False) -> Result:
204
223
  if not is_valid_id(self.model_id):
205
224
  raise RuntimeError("Please choose valid model to apply. [try list_models()]")
206
225
 
@@ -208,7 +227,10 @@ class AsyncMostClient(object):
208
227
  raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
209
228
 
210
229
  resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply_async")
211
- return self.retort.load(resp.json(), Result)
230
+ result = self.retort.load(resp.json(), Result)
231
+ if modify_scores:
232
+ result = self.score_modifier.modify(result)
233
+ return result
212
234
 
213
235
  async def get_job_status(self, audio_id) -> JobStatus:
214
236
  if not is_valid_id(self.model_id):
@@ -220,7 +242,8 @@ class AsyncMostClient(object):
220
242
  resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply_status")
221
243
  return self.retort.load(resp.json(), JobStatus)
222
244
 
223
- async def fetch_results(self, audio_id) -> Result:
245
+ async def fetch_results(self, audio_id,
246
+ modify_scores: bool = False) -> Result:
224
247
  if not is_valid_id(self.model_id):
225
248
  raise RuntimeError("Please choose valid model to apply. [try list_models()]")
226
249
 
@@ -228,7 +251,10 @@ class AsyncMostClient(object):
228
251
  raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
229
252
 
230
253
  resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/results")
231
- return self.retort.load(resp.json(), Result)
254
+ result = self.retort.load(resp.json(), Result)
255
+ if modify_scores:
256
+ result = self.score_modifier.modify(result)
257
+ return result
232
258
 
233
259
  async def fetch_text(self, audio_id) -> Result:
234
260
  if not is_valid_id(self.model_id):
@@ -0,0 +1,23 @@
1
+ import dataclasses
2
+ from typing import Dict, Tuple, List, Optional
3
+
4
+ from .types import Result, ScriptScoreMapping
5
+
6
+
7
+ class ScoreCalculation:
8
+ def __init__(self, score_mapping: List[ScriptScoreMapping]):
9
+ super(ScoreCalculation, self).__init__()
10
+ self.score_mapping = {
11
+ (sm.column, sm.subcolumn, sm.from_score): sm.to_score
12
+ for sm in score_mapping
13
+ }
14
+
15
+ def modify(self, result: Optional[Result]):
16
+ if result is None:
17
+ return None
18
+ result = dataclasses.replace(result)
19
+ for column_result in result.results:
20
+ for subcolumn_result in column_result.subcolumns:
21
+ subcolumn_result.score = self.score_mapping[(column_result.name, subcolumn_result.name, subcolumn_result.score)]
22
+
23
+ return result
@@ -53,6 +53,15 @@ class Script(DataClassJsonMixin):
53
53
  columns: List[Column]
54
54
 
55
55
 
56
+ @dataclass_json
57
+ @dataclass
58
+ class ScriptScoreMapping(DataClassJsonMixin):
59
+ column: str
60
+ subcolumn: str
61
+ from_score: int
62
+ to_score: int
63
+
64
+
56
65
  @dataclass_json
57
66
  @dataclass
58
67
  class JobStatus(DataClassJsonMixin):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: most-client
3
- Version: 1.0.19
3
+ Version: 1.0.20
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
@@ -5,6 +5,7 @@ setup.py
5
5
  most/__init__.py
6
6
  most/api.py
7
7
  most/async_api.py
8
+ most/score_calculation.py
8
9
  most/types.py
9
10
  most_client.egg-info/PKG-INFO
10
11
  most_client.egg-info/SOURCES.txt
@@ -8,7 +8,7 @@ with open('requirements.txt', 'r') as f:
8
8
 
9
9
  setup(
10
10
  name='most-client',
11
- version='1.0.19',
11
+ version='1.0.20',
12
12
  python_requires=f'>=3.6',
13
13
  description='Most AI API for https://the-most.ai',
14
14
  url='https://github.com/the-most-ai/most-client',
File without changes
File without changes
File without changes