Batch
HumeBatchClient
class HumeBatchClient(ClientBase)
Example
from hume import HumeBatchClient
from hume.models.config import FaceConfig
from hume.models.config import ProsodyConfig
client = HumeBatchClient("<your-api-key>")
urls = ["https://storage.googleapis.com/hume-test-data/video/armisen-clip.mp4"]
configs = [FaceConfig(identify_faces=True), ProsodyConfig()]
job = client.submit_job(urls, configs)
print(job)
print("Running...")
job.await_complete()
job.download_predictions("predictions.json")
print("Predictions downloaded to predictions.json")
job.download_artifacts("artifacts.zip")
print("Artifacts downloaded to artifacts.zip")
__init__
Construct a HumeBatchClient.
def __init__(api_key: str, *args: Any, timeout: int = 10, **kwargs: Any)
Arguments:
api_key
str - Hume API key.timeout
int - Time in seconds before canceling long-running Hume API requests.
get_api_type
Get the ApiType of the client.
@classmethod
def get_api_type(cls) -> ApiType
Returns:
ApiType
- API type of the client.
get_job
Rehydrate a job based on a Job ID.
def get_job(job_id: str) -> BatchJob
Arguments:
job_id
str - ID of the job to rehydrate.
Returns:
BatchJob
- Job associated with the given ID.
BatchJob
class BatchJob()
__init__
Construct a BatchJob.
def __init__(client: "HumeBatchClient", job_id: str)
Arguments:
client
HumeBatchClient - HumeBatchClient instance.job_id
str - Job ID.
get_status
Get the status of the job.
def get_status() -> BatchJobStatus
Returns:
BatchJobStatus
- The status of theBatchJob
.
get_predictions
Get BatchJob
predictions.
def get_predictions() -> Any
Returns:
Any
- Predictions for theBatchJob
.
download_predictions
Download BatchJob
predictions file.
def download_predictions(filepath: Union[str, Path]) -> None
Arguments:
filepath
Union[str, Path] - Filepath where predictions will be downloaded.
download_artifacts
Download BatchJob
artifacts zip file.
def download_artifacts(filepath: Union[str, Path]) -> None
Arguments:
filepath
Optional[Union[str, Path]] - Filepath where artifacts will be downloaded.
get_details
Get details for the BatchJob.
def get_details() -> BatchJobDetails
Note that the details for a job may be fetched before the job has completed.
You may want to use job.await_complete()
which will wait for the job to
reach a terminal state before returning.
Returns:
BatchJobDetails
- Details for theBatchJob
.
await_complete
Block until the job has reached a terminal status.
def await_complete(timeout: int = 300) -> BatchJobDetails
Arguments:
timeout
int - Maximum time in seconds to await. If the timeout is reached
before the job reaches a terminal state the job will continue to be processed,
but aHumeClientException
will be raised to the caller ofawait_complete
.
Raises:
ValueError
- If the timeout is not valid.
Returns:
BatchJobDetails
- Details for theBatchJob
.
__repr__
Get the string representation of the BatchJob
.
def __repr__() -> str
Returns:
The the string representation of the BatchJob
.
BatchJobStatus
class BatchJobStatus(Enum)
is_terminal
Check if a status is "terminal".
@classmethod
def is_terminal(cls, status: "BatchJobStatus") -> bool
Arguments:
status
BatchJobStatus - Status to check.
Returns:
bool
- Whether the status is "terminal".
from_str
Convert a status to a string.
@classmethod
def from_str(cls, status: str) -> "BatchJobStatus"
Arguments:
status
str - Status to convert.
Returns:
BatchJobStatus
- The enum variant for the given string.
BatchJobState
@dataclass
class BatchJobState()
Arguments:
status
BatchJobStatus - Status of the batch job.created_timestamp_ms
Optional[int] - Time when job was created.started_timestamp_ms
Optional[int] - Time when job started.ended_timestamp_ms
Optional[int] - Time when job ended.
BatchJobDetails
class BatchJobDetails()
__init__
Construct a BatchJobDetails.
def __init__(*,
configs: Dict[ModelType, ModelConfigBase],
urls: List[str],
files: List[str],
state: BatchJobState,
callback_url: Optional[str] = None,
notify: bool = False)
Arguments:
configs
Dict[ModelType, ModelConfigBase] - Configurations for theBatchJob
.urls
List[str] - URLs processed in theBatchJob
.files
List[str] - Files processed in theBatchJob
.state
BatchJobState - State ofBatchJob
.callback_url
Optional[str] - A URL to which a POST request is sent upon job completion.notify
bool - Whether an email notification should be sent upon job completion.
from_response
Construct a BatchJobDetails
from a batch API job response.
@classmethod
def from_response(cls, response: Any) -> "BatchJobDetails"
Arguments:
response
Any - Batch API job response.
Returns:
BatchJobDetails
- ABatchJobDetails
based on a batch API job response.
get_status
Get the status of the job
def get_status() -> BatchJobStatus
Returns:
BatchJobStatus
- The status of theBatchJob
.
get_run_time_ms
Get the total time in milliseconds it took for the job to run if the job is in a terminal state
def get_run_time_ms() -> Optional[int]
Returns:
Optional[int]
- Time in milliseconds it took for the job to run. If the job is not in a terminal
state thenNone
is returned.
get_created_time
Get the time the job was created.
def get_created_time() -> Optional[datetime]
Returns:
Optional[datetime]
- Datetime when the job was created. If the job has not started
thenNone
is returned.
get_started_time
Get the time the job started running.
def get_started_time() -> Optional[datetime]
Returns:
Optional[datetime]
- Datetime when the job started running. If the job has not started
thenNone
is returned.
get_ended_time
Get the time the job stopped running if the job is in a terminal state.
def get_ended_time() -> Optional[datetime]
Returns:
Optional[datetime]
- Datetime when the job started running. If the job is not in a terminal
state thenNone
is returned.
TranscriptionConfig
Configuration for speech transcription.
@dataclass
class TranscriptionConfig(ConfigBase["TranscriptionConfig"])
Arguments:
language
Optional[str] - By default, we use an automated language detection method for our
Speech Prosody, Language, and NER models. However, if you know what language is being spoken
in your media samples, you can specify it via its BCP-47 tag and potentially obtain more accurate results.
You can specify any of the following:zh
,da
,nl
,en
,en-AU
,
en-IN
,en-NZ
,en-GB
,fr
,fr-CA
,de
,hi
,hi-Latn
,id
,it
,ja
,ko
,no
,
pl
,pt
,pt-BR
,pt-PT
,ru
,es
,es-419
,sv
,ta
,tr
, oruk
.
Updated 3 months ago