Skip to content

Commit

Permalink
add text bytes as well
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-chung committed Dec 4, 2023
1 parent 5da1d57 commit 8af4b6a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions clarifai/client/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,17 @@ def get_text_input(input_id: str, raw_text: str, dataset_id: str = None,
@staticmethod
def get_multimodal_input(input_id: str,
raw_text: str,
text_bytes: bytes = None,
image_url: str = None,
image_bytes: bytes = None,
dataset_id: str = None,
**kwargs) -> Text:
"""Create input proto for text data type from raw text and image from bytes or url.
"""Create input proto for text and image from bytes or url.
Args:
input_id (str): The input ID for the input to create.
raw_text (str): The raw text input.
text_bytes (str): The bytes for the text.
image_url (str): The url for the image.
image_bytes (str): The bytes for the image.
dataset_id (str): The dataset ID for the dataset to add the input to.
Expand All @@ -304,8 +306,10 @@ def get_multimodal_input(input_id: str,
>>> from clarifai.client.input import Inputs
>>> input_protos = Inputs.get_multimodal_input(input_id = 'demo', raw_text = 'What time of day is it?', image_url='https://samples.clarifai.com/metro-north.jpg')
"""
image_pb = resources_pb2.Image(base64=image_bytes) if image_bytes and not image_url else None
image_pb = resources_pb2.Image(url=image_url) if image_url and not image_bytes else None
# Will only use URL if both bytes and URL are supplied.
image_pb = resources_pb2.Image(base64=image_bytes) if image_bytes else None
image_pb = resources_pb2.Image(url=image_url) if image_url else None
text_pb = resources_pb2.Text(raw=text_bytes) if text_bytes else None
text_pb = resources_pb2.Text(raw=raw_text)
return Inputs._get_proto(
input_id=input_id, dataset_id=dataset_id, imagepb=image_pb, text_pb=text_pb, **kwargs)
Expand Down

0 comments on commit 8af4b6a

Please sign in to comment.