API Reference
This is the API Reference documentation extracted from the source code.
User
- class User(user_id: str = '', **kwargs)[source]
User is a class that provides access to Clarifai API endpoints related to user information.
- __init__(user_id: str = '', **kwargs)[source]
Initializes an User object.
- Parameters:
user_id (str) – The user ID for the user to interact with.
**kwargs – Additional keyword arguments to be passed to the ClarifaiAuthHelper.
- app(app_id: str, **kwargs) App[source]
Returns an App object for the specified app ID.
- Parameters:
app_id (str) – The app ID for the app to interact with.
**kwargs – Additional keyword arguments to be passed to the App.
- Returns:
An App object for the specified app ID.
- Return type:
Example
>>> from clarifai.client.user import User >>> app = User("user_id").app("app_id")
- create_app(app_id: str, base_workflow: str = 'Language-Understanding', **kwargs) App[source]
Creates an app for the user.
- Parameters:
app_id (str) – The app ID for the app to create.
base_workflow (str) – The base workflow to use for the app.(Examples: ‘Universal’, ‘Empty’, ‘General’)
**kwargs – Additional keyword arguments to be passed to the App.
- Returns:
An App object for the specified app ID.
- Return type:
Example
>>> from clarifai.client.user import User >>> client = User(user_id="user_id") >>> app = client.create_app(app_id="app_id",base_workflow="Universal")
- delete_app(app_id: str) None[source]
Deletes an app for the user.
- Parameters:
app_id (str) – The app ID for the app to delete.
Example
>>> from clarifai.client.user import User >>> user = User("user_id").delete_app("app_id")
- list_apps(filter_by: Dict[str, Any] = {}) List[App][source]
Lists all the apps for the user.
- Parameters:
filter_by (dict) – A dictionary of filters to be applied to the list of apps.
- Returns:
A list of App objects for the user.
- Return type:
list of App
Example
>>> from clarifai.client.user import User >>> apps = User("user_id").list_apps()
App
- class App(url_init: str = '', app_id: str = '', **kwargs)[source]
App is a class that provides access to Clarifai API endpoints related to App information.
- __init__(url_init: str = '', app_id: str = '', **kwargs)[source]
Initializes an App object.
- Parameters:
url_init (str) – The URL to initialize the app object.
app_id (str) – The App ID for the App to interact with.
**kwargs – Additional keyword arguments to be passed to the ClarifaiAuthHelper. - name (str): The name of the app. - description (str): The description of the app.
- create_dataset(dataset_id: str, **kwargs) Dataset[source]
Creates a dataset for the app.
- Parameters:
dataset_id (str) – The dataset ID for the dataset to create.
**kwargs – Additional keyword arguments to be passed to the Dataset.
- Returns:
A Dataset object for the specified dataset ID.
- Return type:
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> dataset = app.create_dataset(dataset_id="dataset_id")
- create_model(model_id: str, **kwargs) Model[source]
Creates a model for the app.
- Parameters:
model_id (str) – The model ID for the model to create.
**kwargs – Additional keyword arguments to be passed to the Model.
- Returns:
A Model object for the specified model ID.
- Return type:
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> model = app.create_model(model_id="model_id")
- create_module(module_id: str, description: str, **kwargs) Module[source]
Creates a module for the app.
- Parameters:
module_id (str) – The module ID for the module to create.
description (str) – The description of the module to create.
**kwargs – Additional keyword arguments to be passed to the module.
- Returns:
A Module object for the specified module ID.
- Return type:
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> module = app.create_module(module_id="module_id")
- create_workflow(workflow_id: str, **kwargs) Workflow[source]
Creates a workflow for the app.
- Parameters:
workflow_id (str) – The workflow ID for the workflow to create.
**kwargs – Additional keyword arguments to be passed to the workflow.
- Returns:
A Workflow object for the specified workflow ID.
- Return type:
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> workflow = app.create_workflow(workflow_id="workflow_id")
- dataset(dataset_id: str, **kwargs) Dataset[source]
Returns a Dataset object for the existing dataset ID.
- Parameters:
dataset_id (str) – The dataset ID for the dataset to interact with.
- Returns:
A Dataset object for the existing dataset ID.
- Return type:
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> dataset = app.dataset(dataset_id="dataset_id")
- delete_dataset(dataset_id: str) None[source]
Deletes an dataset for the user.
- Parameters:
dataset_id (str) – The dataset ID for the app to delete.
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> app.delete_dataset(dataset_id="dataset_id")
- delete_model(model_id: str) None[source]
Deletes an model for the user.
- Parameters:
model_id (str) – The model ID for the app to delete.
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> app.delete_model(model_id="model_id")
- delete_module(module_id: str) None[source]
Deletes an module for the user.
- Parameters:
module_id (str) – The module ID for the app to delete.
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> app.delete_module(module_id="module_id")
- delete_workflow(workflow_id: str) None[source]
Deletes an workflow for the user.
- Parameters:
workflow_id (str) – The workflow ID for the app to delete.
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> app.delete_workflow(workflow_id="workflow_id")
- list_datasets() List[Dataset][source]
Lists all the datasets for the app.
- Returns:
A list of Dataset objects for the datasets in the app.
- Return type:
List[Dataset]
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> all_datasets = app.list_datasets()
- list_installed_module_versions(filter_by: Dict[str, Any] = {}) List[Module][source]
Lists all installed module versions in the app.
- Parameters:
filter_by (dict) – A dictionary of filters to apply to the list of installed module versions.
- Returns:
A list of Module objects for the installed module versions in the app.
- Return type:
List[Module]
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> all_installed_module_versions = app.list_installed_module_versions()
- list_models(filter_by: Dict[str, Any] = {}, only_in_app: bool = True) List[Model][source]
Lists all the available models for the user.
- Parameters:
filter_by (dict) – A dictionary of filters to apply to the list of models.
only_in_app (bool) – If True, only return models that are in the app.
- Returns:
A list of Model objects for the models in the app.
- Return type:
List[Model]
Example
>>> from clarifai.client.user import User >>> app = User(user_id="user_id").app(app_id="app_id") >>> all_models = app.list_models()
- list_modules(filter_by: Dict[str, Any] = {}, only_in_app: bool = True) List[Module][source]
Lists all the available modules for the user.
- Parameters:
filter_by (dict) – A dictionary of filters to apply to the list of modules.
only_in_app (bool) – If True, only return modules that are in the app.
- Returns:
A list of Module objects for the modules in the app.
- Return type:
List[Module]
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> all_modules = app.list_modules()
- list_workflows(filter_by: Dict[str, Any] = {}, only_in_app: bool = True) List[Workflow][source]
Lists all the available workflows for the user.
- Parameters:
filter_by (dict) – A dictionary of filters to apply to the list of workflows.
only_in_app (bool) – If True, only return workflows that are in the app.
- Returns:
A list of Workflow objects for the workflows in the app.
- Return type:
List[Workflow]
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> all_workflows = app.list_workflows()
- model(model_id: str, model_version_id: str = '', **kwargs) Model[source]
Returns a Model object for the existing model ID.
- Parameters:
model_id (str) – The model ID for the model to interact with.
model_version_id (str) – The model version ID for the model version to interact with.
- Returns:
A Model object for the existing model ID.
- Return type:
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> model_v1 = app.model(model_id="model_id", model_version_id="model_version_id")
- module(module_id: str, module_version_id: str = '', **kwargs) Module[source]
Returns a Module object for the existing module ID.
- Parameters:
module_id (str) – The module ID for the module to interact with.
module_version_id (str) – The module version ID for the module version to interact with.
- Returns:
A Module object for the existing module ID.
- Return type:
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> module = app.module(module_id="module_id", module_version_id="module_version_id")
- workflow(workflow_id: str, **kwargs) Workflow[source]
Returns a workflow object for the existing workflow ID.
- Parameters:
workflow_id (str) – The workflow ID for the workflow to interact with.
- Returns:
A Workflow object for the existing workflow ID.
- Return type:
Example
>>> from clarifai.client.app import App >>> app = App(app_id="app_id", user_id="user_id") >>> workflow = app.workflow(workflow_id="workflow_id")
Dataset
- class Dataset(url_init: str = '', dataset_id: str = '', **kwargs)[source]
Dataset is a class that provides access to Clarifai API endpoints related to Dataset information.
- __init__(url_init: str = '', dataset_id: str = '', **kwargs)[source]
Initializes a Dataset object.
- Parameters:
url_init (str) – The URL to initialize the dataset object.
dataset_id (str) – The Dataset ID within the App to interact with.
**kwargs – Additional keyword arguments to be passed to the ClarifaiAuthHelper.
- upload_dataset(task: str, split: str, module_dir: str = None, dataset_loader: str = None, chunk_size: int = 128) None[source]
Uploads a dataset to the app.
- Parameters:
task (str) – task type(text_clf, visual-classification, visual_detection, visual_segmentation, visual-captioning)
split (str) – split type(train, test, val)
module_dir (str) – path to the module directory
dataset_loader (str) – name of the dataset loader
chunk_size (int) – chunk size for concurrent upload of inputs and annotations
- upload_from_csv(csv_path: str, input_type: str = 'text', labels: bool = True, chunk_size: int = 128) None[source]
Uploads dataset from a csv file.
- Parameters:
csv_path (str) – path to the csv file
input_type (str) – type of the dataset(text, image)
labels (bool) – True if csv file has labels column
chunk_size (int) – chunk size for concurrent upload of inputs and annotations
Example
>>> from clarifai.client.dataset import Dataset >>> dataset = Dataset(user_id = 'user_id', app_id = 'demo_app', dataset_id = 'demo_dataset') >>> dataset.upload_from_csv(csv_path='csv_path', labels=True)
Note: csv file should have either one(input) or two columns(input, labels).
- upload_from_folder(folder_path: str, input_type: str, labels: bool = False, chunk_size: int = 128) None[source]
Upload dataset from folder.
- Parameters:
folder_path (str) – Path to the folder containing images.
input_type (str) – type of the dataset(text, image)
labels (bool) – True if folder name is the label for the inputs
chunk_size (int) – chunk size for concurrent upload of inputs and annotations
Example
>>> from clarifai.client.dataset import Dataset >>> dataset = Dataset(user_id = 'user_id', app_id = 'demo_app', dataset_id = 'demo_dataset') >>> dataset.upload_from_folder(folder_path='folder_path', input_type='text', labels=True)
Note: The filename is used as the input_id.
Input
- class Inputs(user_id: str = '', app_id: str = '', logger_level: str = 'INFO', **kwargs)[source]
Inputs is a class that provides access to Clarifai API endpoints related to Input information.
- __init__(user_id: str = '', app_id: str = '', logger_level: str = 'INFO', **kwargs)[source]
Initializes an Input object.
- Parameters:
user_id (str) – A user ID for authentication.
app_id (str) – An app ID for the application to interact with.
**kwargs – Additional keyword arguments to be passed to the Input
- delete_inputs(inputs: List[Input]) None[source]
Delete list of input objects from the app.
- Parameters:
input_ids (Input) – List of input objects to delete.
Example
>>> from clarifai.client.user import User >>> input_obj = User(user_id="user_id").app(app_id="app_id").inputs() >>> input_obj.delete_inputs(input_obj.list_inputs())
- get_annotation_proto(input_id: str, label: str, annotations: List) Annotation[source]
Create an annotation proto for each bounding box, label input pair.
- Parameters:
input_id (str) – The input ID for the annotation to create.
label (str) – annotation label
annotations (List) – a list of a single bbox’s coordinates. # Annotations ordering: [xmin, ymin, xmax, ymax]
- Returns:
An annotation object for the specified input ID.
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> input_obj.get_annotation_proto(input_id='demo', label='demo', annotations=[x_min, y_min, x_max, y_max])
- get_image_inputs_from_folder(folder_path: str, dataset_id: str = None, labels: bool = False) List[Input][source]
Create input protos for image data type from folder.
- Parameters:
folder_path (str) – Path to the folder containing images.
- Returns:
A list of Input objects for the specified folder.
- Return type:
list of Input
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> input_protos = input_obj.get_image_inputs_from_folder(folder_path='demo_folder')
- get_input_from_bytes(input_id: str, image_bytes: bytes = None, video_bytes: bytes = None, audio_bytes: bytes = None, dataset_id: str = None, **kwargs) Input[source]
Create input proto from bytes.
- Parameters:
input_id (str) – The input ID for the input to create.
image_bytes (str) – The bytes for the image.
video_bytes (str) – The bytes for the video.
audio_bytes (str) – The bytes for the audio.
dataset_id (str) – The dataset ID for the dataset to add the input to.
- Returns:
An Input object for the specified input ID.
- Return type:
Input
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> image = open('demo.jpg', 'rb').read() >>> video = open('demo.mp4', 'rb').read() >>> input_proto = input_obj.get_input_from_bytes(input_id = 'demo',image_bytes =image, video_bytes=video)
- get_input_from_file(input_id: str, image_file: str = None, video_file: str = None, audio_file: str = None, dataset_id: str = None, **kwargs) Input[source]
Create input proto from files.
- Parameters:
input_id (str) – The input ID for the input to create.
image_file (str) – The url for the image.
video_file (str) – The url for the video.
audio_file (str) – The url for the audio.
dataset_id (str) – The dataset ID for the dataset to add the input to.
- Returns:
An Input object for the specified input ID.
- Return type:
Input
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> input_proto = input_obj.get_input_from_file(input_id = 'demo', video_file='file_path')
- get_input_from_url(input_id: str, image_url: str = None, video_url: str = None, audio_url: str = None, text_url: str = None, dataset_id: str = None, **kwargs) Input[source]
Create input proto from url.
- Parameters:
input_id (str) – The input ID for the input to create.
image_url (str) – The url for the image.
video_url (str) – The url for the video.
audio_url (str) – The url for the audio.
text_url (str) – The url for the text. dataset_id (str): The dataset ID for the dataset to add the input to.
- Returns:
An Input object for the specified input ID.
- Return type:
Input
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> input_proto = input_obj.get_input_from_url(input_id = 'demo', image_url='https://samples.clarifai.com/metro-north.jpg')
- get_mask_proto(input_id: str, label: str, polygons: List[List[float]]) Annotation[source]
Create an annotation proto for each polygon box, label input pair.
- Parameters:
input_id (str) – The input ID for the annotation to create.
label (str) – annotation label
polygons (List) – Polygon x,y points iterable
- Returns:
An annotation object for the specified input ID.
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> input_obj.get_mask_proto(input_id='demo', label='demo', polygons=[[[x,y],...,[x,y]],...])
- get_text_input(input_id: str, raw_text: str, dataset_id: str = None, **kwargs) Text[source]
Create input proto for text data type from rawtext.
- Parameters:
input_id (str) – The input ID for the input to create.
raw_text (str) – The raw text input.
dataset_id (str) – The dataset ID for the dataset to add the input to.
**kwargs – Additional keyword arguments to be passed to the Input
- Returns:
An Input object for the specified input ID.
- Return type:
Text
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> input_protos = input_obj.get_text_input(input_id = 'demo', raw_text = 'This is a test')
- get_text_input_from_csv(csv_path: str, dataset_id: str = None, labels: str = True) List[Text][source]
Create input proto for text data type from cscv.
- Parameters:
csv_path (str) – Path to the csv file.
dataset_id (str) – The dataset ID for the dataset to add the input to.
labels (str) – True if csv file has labels column.
- Returns:
List of inputs
- Return type:
inputs
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> input_protos = input_obj.get_text_input_from_csv(csv_path = 'filepath')
- get_text_inputs_from_folder(folder_path: str, dataset_id: str = None, labels: bool = False) List[Text][source]
Create input protos for text data type from folder.
- Parameters:
folder_path (str) – Path to the folder containing text.
- Returns:
A list of Input objects for the specified folder.
- Return type:
list of Input
Example
>>> from clarifai.client.input import Input >>> input_obj = Input() >>> input_protos = input_obj.get_text_inputs_from_folder(folder_path='demo_folder')
- list_inputs() List[Input][source]
Lists all the inputs for the app.
- Returns:
A list of Input objects for the app.
- Return type:
list of Input
Example
>>> from clarifai.client.user import User >>> input_obj = User(user_id="user_id").app(app_id="app_id").inputs() >>> input_obj.list_inputs()
- upload_annotations(batch_annot: List[Annotation], show_log: bool = True) List[Annotation] | List[None][source]
Upload image annotations to app.
- Parameters:
batch_annot – annot batch protos
- Returns:
failed annot upload
- Return type:
retry_upload
- upload_from_bytes(input_id: str, image_bytes: bytes = None, video_bytes: bytes = None, audio_bytes: bytes = None, dataset_id: str = None, **kwargs) str[source]
Upload input from bytes.
- Parameters:
input_id (str) – The input ID for the input to create.
image_bytes (str) – The bytes for the image.
video_bytes (str) – The bytes for the video.
audio_bytes (str) – The bytes for the audio.
dataset_id (str) – The dataset ID for the dataset to add the input to.
- Returns:
job id for the upload request.
- Return type:
input_job_id
Example
>>> from clarifai.client.input import Input >>> input_obj = Input(user_id = 'user_id', app_id = 'demo_app') >>> image = open('demo.jpg', 'rb').read() >>> input_obj.upload_from_bytes(input_id='demo', image_bytes=image)
- upload_from_file(input_id: str, image_file: str = None, video_file: str = None, audio_file: str = None, dataset_id: str = None, **kwargs) str[source]
Upload input from file.
- Parameters:
input_id (str) – The input ID for the input to create.
image_file (str) – The file for the image.
video_file (str) – The file for the video.
audio_file (str) – The file for the audio.
dataset_id (str) – The dataset ID for the dataset to add the input to.
- Returns:
job id for the upload request.
- Return type:
input_job_id
Example
>>> from clarifai.client.input import Input >>> input_obj = Input(user_id = 'user_id', app_id = 'demo_app') >>> input_obj.upload_from_file(input_id='demo', audio_file='demo.mp3')
- upload_from_url(input_id: str, image_url: str = None, video_url: str = None, audio_url: str = None, text_url: str = None, dataset_id: str = None, **kwargs) str[source]
Upload input from url.
- Parameters:
input_id (str) – The input ID for the input to create.
image_url (str) – The url for the image.
video_url (str) – The url for the video.
audio_url (str) – The url for the audio.
text_url (str) – The url for the text.
dataset_id (str) – The dataset ID for the dataset to add the input to.
- Returns:
job id for the upload request.
- Return type:
input_job_id
Example
>>> from clarifai.client.input import Input >>> input_obj = Input(user_id = 'user_id', app_id = 'demo_app') >>> input_obj.upload_from_url(input_id='demo', image_url='https://samples.clarifai.com/metro-north.jpg')
- upload_inputs(inputs: List[Input], show_log: bool = True) str[source]
Upload list of input objects to the app.
- Parameters:
inputs (list) – List of input objects to upload.
show_log (bool) – Show upload status log.
- Returns:
job id for the upload request.
- Return type:
input_job_id
- upload_text(input_id: str, raw_text: str, dataset_id: str = None, **kwargs) str[source]
Upload text from raw text.
- Parameters:
input_id (str) – The input ID for the input to create.
raw_text (str) – The raw text.
dataset_id (str) – The dataset ID for the dataset to add the input to.
- Returns:
job id for the upload request.
- Return type:
input_job_id (str)
Example
>>> from clarifai.client.input import Input >>> input_obj = Input(user_id = 'user_id', app_id = 'demo_app') >>> input_obj.upload_text(input_id = 'demo', raw_text = 'This is a test')
Lister
- class Lister(page_size: int = 16)[source]
Lister class for obtaining paginated results from the Clarifai API.
- list_all_pages_generator(endpoint: Callable, proto_message: Any, request_data: Dict[str, Any]) Generator[Dict[str, Any], None, None][source]
Lists all pages of a resource.
- Parameters:
endpoint (Callable) – The endpoint to call.
proto_message (Any) – The proto message to use.
request_data (dict) – The request data to use.
- Yields:
response_dict – The next item in the listing.
Model
- class Model(url_init: str = '', model_id: str = '', model_version: Dict = {'id': ''}, output_config: Dict = {'min_value': 0}, **kwargs)[source]
Model is a class that provides access to Clarifai API endpoints related to Model information.
- __init__(url_init: str = '', model_id: str = '', model_version: Dict = {'id': ''}, output_config: Dict = {'min_value': 0}, **kwargs)[source]
Initializes a Model object.
- Parameters:
url_init (str) – The URL to initialize the model object.
model_id (str) – The Model ID to interact with.
model_version (dict) – The Model Version to interact with.
output_config (dict) – The output config to interact with. min_value (float): The minimum value of the prediction confidence to filter. max_concepts (int): The maximum number of concepts to return. select_concepts (list[Concept]): The concepts to select. sample_ms (int): The number of milliseconds to sample.
**kwargs – Additional keyword arguments to be passed to the ClarifaiAuthHelper.
- list_versions() List[Model][source]
Lists all the versions for the model.
- Returns:
A list of Model objects for the versions of the model.
- Return type:
List[Model]
Example
>>> from clarifai.client.model import Model >>> model = Model("model_url") # Example URL: https://clarifai.com/clarifai/main/models/general-image-recognition or >>> model = Model(model_id='model_id', user_id='user_id', app_id='app_id') >>> all_model_versions = model.list_versions()
- predict(inputs: List[Input])[source]
Predicts the model based on the given inputs.
- Parameters:
inputs (list[Input]) – The inputs to predict, must be less than 128.
- predict_by_bytes(input_bytes: bytes, input_type: str)[source]
Predicts the model based on the given bytes.
- Parameters:
input_bytes (bytes) – File Bytes to predict on.
input_type (str) – The type of input. Can be ‘image’, ‘text’, ‘video’ or ‘audio’.
Example
>>> from clarifai.client.model import Model >>> model = Model("https://clarifai.com/anthropic/completion/models/claude-v2") >>> model_prediction = model.predict_by_bytes(b'Write a tweet on future of AI', 'text')
- predict_by_filepath(filepath: str, input_type: str)[source]
Predicts the model based on the given filepath.
- Parameters:
filepath (str) – The filepath to predict.
input_type (str) – The type of input. Can be ‘image’, ‘text’, ‘video’ or ‘audio.
Example
>>> from clarifai.client.model import Model >>> model = Model("model_url") # Example URL: https://clarifai.com/clarifai/main/models/general-image-recognition or >>> model = Model(model_id='model_id', user_id='user_id', app_id='app_id') >>> model_prediction = model.predict_by_filepath('/path/to/image.jpg', 'image') >>> model_prediction = model.predict_by_filepath('/path/to/text.txt', 'text')
- predict_by_url(url: str, input_type: str)[source]
Predicts the model based on the given URL.
- Parameters:
url (str) – The URL to predict.
input_type (str) – The type of input. Can be ‘image’, ‘text’, ‘video’ or ‘audio.
Example
>>> from clarifai.client.model import Model >>> model = Model("model_url") # Example URL: https://clarifai.com/clarifai/main/models/general-image-recognition or >>> model = Model(model_id='model_id', user_id='user_id', app_id='app_id') >>> model_prediction = model.predict_by_url('url', 'image')
Workflow
- class Workflow(url_init: str = '', workflow_id: str = '', workflow_version: Dict = {'id': ''}, output_config: Dict = {'min_value': 0}, **kwargs)[source]
Workflow is a class that provides access to Clarifai API endpoints related to Workflow information.
- __init__(url_init: str = '', workflow_id: str = '', workflow_version: Dict = {'id': ''}, output_config: Dict = {'min_value': 0}, **kwargs)[source]
Initializes a Workflow object.
- Parameters:
url_init (str) – The URL to initialize the workflow object.
workflow_id (str) – The Workflow ID to interact with.
workflow_version (dict) – The Workflow Version to interact with.
output_config (dict) – The output config to interact with. min_value (float): The minimum value of the prediction confidence to filter. max_concepts (int): The maximum number of concepts to return. select_concepts (list[Concept]): The concepts to select. sample_ms (int): The number of milliseconds to sample.
**kwargs – Additional keyword arguments to be passed to the ClarifaiAuthHelper.
- list_versions() List[Workflow][source]
Lists all the versions of the workflow.
- Returns:
A list of Workflow objects.
- Return type:
list[Workflow]
Example
>>> from clarifai.client.workflow import Workflow >>> workflow = Workflow(user_id='user_id', app_id='app_id', workflow_id='workflow_id') >>> workflow_versions = workflow.list_versions()
- predict(inputs: List[Input])[source]
Predicts the workflow based on the given inputs.
- Parameters:
inputs (list[Input]) – The inputs to predict.
- predict_by_bytes(input_bytes: bytes, input_type: str)[source]
Predicts the workflow based on the given bytes.
- Parameters:
input_bytes (bytes) – Bytes to predict on.
input_type (str) – The type of input. Can be ‘image’, ‘text’, ‘video’ or ‘audio.
- predict_by_filepath(filepath: str, input_type: str)[source]
Predicts the workflow based on the given filepath.
- Parameters:
filepath (str) – The filepath to predict.
input_type (str) – The type of input. Can be ‘image’, ‘text’, ‘video’ or ‘audio.
Example
>>> from clarifai.client.workflow import Workflow >>> workflow = Workflow("workflow_url") # Example: https://clarifai.com/clarifai/main/workflows/Face-Sentiment or >>> workflow = Workflow(user_id='user_id', app_id='app_id', workflow_id='workflow_id') >>> workflow_prediction = workflow.predict_by_filepath('filepath', 'image')
- predict_by_url(url: str, input_type: str)[source]
Predicts the workflow based on the given URL.
- Parameters:
url (str) – The URL to predict.
input_type (str) – The type of input. Can be ‘image’, ‘text’, ‘video’ or ‘audio.
Example
>>> from clarifai.client.workflow import Workflow >>> workflow = Workflow("workflow_url") # Example: https://clarifai.com/clarifai/main/workflows/Face-Sentiment or >>> workflow = Workflow(user_id='user_id', app_id='app_id', workflow_id='workflow_id') >>> workflow_prediction = workflow.predict_by_url('url', 'image')
Module
- class Module(url_init: str = '', module_id: str = '', module_version: Dict = {'id': ''}, **kwargs)[source]
Module is a class that provides access to Clarifai API endpoints related to Module information.
- __init__(url_init: str = '', module_id: str = '', module_version: Dict = {'id': ''}, **kwargs)[source]
Initializes a Module object.
- Parameters:
url_init (str) – The URL to initialize the module object.
module_id (str) – The Module ID to interact with.
module_version (dict) – The Module Version to interact with.
**kwargs – Additional keyword arguments to be passed to the ClarifaiAuthHelper.
- list_versions() List[Module][source]
Lists all the module versions for the module.
- Returns:
A list of Module objects for versions of the module.
- Return type:
List[Moudle]
Example
>>> from clarifai.client.module import Module >>> module = Module(module_id='module_id', user_id='user_id', app_id='app_id') >>> all_Module_versions = module.list_versions()