25
25
import io
26
26
import os
27
27
import time
28
+ import warnings
28
29
from pathlib import Path
29
30
from typing import Callable , Optional , Union
30
31
31
32
import requests
32
33
from requests import Response
33
34
from requests .exceptions import ConnectionError , HTTPError
34
35
35
- __version__ = importlib .metadata .version ("pyannoteAI " )
36
+ __version__ = importlib .metadata .version ("pyannoteai-sdk " )
36
37
37
38
38
39
class PyannoteAIFailedJob (Exception ):
@@ -47,7 +48,7 @@ class PyannoteAICanceledJob(Exception):
47
48
pass
48
49
49
50
50
- class UploadingCallbackBytesIO (io .BytesIO ):
51
+ class _UploadingCallbackBytesIO (io .BytesIO ):
51
52
"""BytesIO subclass that calls a callback during the upload process
52
53
53
54
Parameters
@@ -93,8 +94,9 @@ class Client:
93
94
94
95
Usage
95
96
-----
97
+
96
98
# instantiate client for pyannoteAI web API
97
- >>> from pyannoteAI import Client
99
+ >>> from pyannoteai.sdk import Client
98
100
>>> client = Client(token="{PYANNOTEAI_API_KEY}")
99
101
100
102
# upload your audio file to the pyannoteAI web API
@@ -204,8 +206,8 @@ def api_key(self, api_key: str) -> None:
204
206
if not api_key :
205
207
raise ValueError (
206
208
"""
207
- Failed to authenticate to pyannoteAI web API. Please create an API key on https://dashboard.pyannote.ai/ and
208
- provide it either via `PYANNOTEAI_API_TOKEN` environment variable or with `token` parameter."""
209
+ Failed to authenticate to pyannoteAI web API. Please create an API key on https://dashboard.pyannote.ai/ and
210
+ provide it either via `PYANNOTEAI_API_TOKEN` environment variable or with `token` parameter."""
209
211
)
210
212
211
213
# store the API key and prepare the headers
@@ -285,9 +287,9 @@ def upload(
285
287
286
288
# for now, only str and Path audio instances are supported
287
289
with open (audio , "rb" ) as f :
288
- # wrap the file object in a UploadingCallbackBytesIO instance
290
+ # wrap the file object in a _UploadingCallbackBytesIO instance
289
291
# to allow calling the hook during the upload process
290
- data = UploadingCallbackBytesIO (callback , total_size , f .read ())
292
+ data = _UploadingCallbackBytesIO (callback , total_size , f .read ())
291
293
292
294
if not (isinstance (media_url , str ) and media_url .startswith ("media://" )):
293
295
raise ValueError (
@@ -312,6 +314,11 @@ def upload(
312
314
# TODO: handle HTTPError returned by the API
313
315
response .raise_for_status ()
314
316
317
+ warnings .warn ("""
318
+ You are using pyannoteAI's temporary storage solution. Your file will be permanently deleted from our servers within 24hs.
319
+ If you are running in production, we highly recommend to use your own storage to reduce network latency and obtain results faster.
320
+ Please check our documentation at https://docs.pyannote.ai/ for more information.""" )
321
+
315
322
return media_url
316
323
317
324
def diarize (
@@ -488,15 +495,16 @@ def retrieve(self, job_id: str, every_seconds: int = 10) -> dict:
488
495
break
489
496
490
497
if job_status == "failed" :
491
- error = job .get ("output" , dict ()).get (
492
- "error" , "Please contact support."
493
- )
498
+ error = job .get ("output" , dict ()).get ("error" , "Please contact support." )
494
499
raise PyannoteAIFailedJob (error , job_id )
495
500
496
501
if job_status == "canceled" :
497
- error = job .get ("output" , dict ()).get (
498
- "error" , "Please contact support."
499
- )
502
+ error = job .get ("output" , dict ()).get ("error" , "Please contact support." )
500
503
raise PyannoteAICanceledJob (error , job_id )
501
504
505
+ warnings .warn ("""
506
+ You are using periodic polling to retrieve results.
507
+ If you are running in production, we highly recommend to setup a webhook server to obtain results faster, as soon as they are available.
508
+ Please check our documentation at https://docs.pyannote.ai/ for more information.""" )
509
+
502
510
return job
0 commit comments