I am done

This commit is contained in:
2024-10-30 22:14:35 +01:00
parent 720dc28c09
commit 40e2a747cf
36901 changed files with 5011519 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,165 @@
# This file is auto-generated by `utils/generate_inference_types.py`.
# Do not modify it manually.
#
# ruff: noqa: F401
from .audio_classification import (
AudioClassificationInput,
AudioClassificationOutputElement,
AudioClassificationOutputTransform,
AudioClassificationParameters,
)
from .audio_to_audio import AudioToAudioInput, AudioToAudioOutputElement
from .automatic_speech_recognition import (
AutomaticSpeechRecognitionEarlyStoppingEnum,
AutomaticSpeechRecognitionGenerationParameters,
AutomaticSpeechRecognitionInput,
AutomaticSpeechRecognitionOutput,
AutomaticSpeechRecognitionOutputChunk,
AutomaticSpeechRecognitionParameters,
)
from .base import BaseInferenceType
from .chat_completion import (
ChatCompletionInput,
ChatCompletionInputFunctionDefinition,
ChatCompletionInputFunctionName,
ChatCompletionInputGrammarType,
ChatCompletionInputMessage,
ChatCompletionInputMessageChunk,
ChatCompletionInputStreamOptions,
ChatCompletionInputToolType,
ChatCompletionInputURL,
ChatCompletionOutput,
ChatCompletionOutputComplete,
ChatCompletionOutputFunctionDefinition,
ChatCompletionOutputLogprob,
ChatCompletionOutputLogprobs,
ChatCompletionOutputMessage,
ChatCompletionOutputToolCall,
ChatCompletionOutputTopLogprob,
ChatCompletionOutputUsage,
ChatCompletionStreamOutput,
ChatCompletionStreamOutputChoice,
ChatCompletionStreamOutputDelta,
ChatCompletionStreamOutputDeltaToolCall,
ChatCompletionStreamOutputFunction,
ChatCompletionStreamOutputLogprob,
ChatCompletionStreamOutputLogprobs,
ChatCompletionStreamOutputTopLogprob,
ChatCompletionStreamOutputUsage,
ToolElement,
)
from .depth_estimation import DepthEstimationInput, DepthEstimationOutput
from .document_question_answering import (
DocumentQuestionAnsweringInput,
DocumentQuestionAnsweringInputData,
DocumentQuestionAnsweringOutputElement,
DocumentQuestionAnsweringParameters,
)
from .feature_extraction import FeatureExtractionInput
from .fill_mask import FillMaskInput, FillMaskOutputElement, FillMaskParameters
from .image_classification import (
ImageClassificationInput,
ImageClassificationOutputElement,
ImageClassificationOutputTransform,
ImageClassificationParameters,
)
from .image_segmentation import ImageSegmentationInput, ImageSegmentationOutputElement, ImageSegmentationParameters
from .image_to_image import ImageToImageInput, ImageToImageOutput, ImageToImageParameters, ImageToImageTargetSize
from .image_to_text import (
ImageToTextEarlyStoppingEnum,
ImageToTextGenerationParameters,
ImageToTextInput,
ImageToTextOutput,
ImageToTextParameters,
)
from .object_detection import (
ObjectDetectionBoundingBox,
ObjectDetectionInput,
ObjectDetectionOutputElement,
ObjectDetectionParameters,
)
from .question_answering import (
QuestionAnsweringInput,
QuestionAnsweringInputData,
QuestionAnsweringOutputElement,
QuestionAnsweringParameters,
)
from .sentence_similarity import SentenceSimilarityInput, SentenceSimilarityInputData
from .summarization import SummarizationInput, SummarizationOutput, SummarizationParameters
from .table_question_answering import (
TableQuestionAnsweringInput,
TableQuestionAnsweringInputData,
TableQuestionAnsweringOutputElement,
)
from .text2text_generation import Text2TextGenerationInput, Text2TextGenerationOutput, Text2TextGenerationParameters
from .text_classification import (
TextClassificationInput,
TextClassificationOutputElement,
TextClassificationOutputTransform,
TextClassificationParameters,
)
from .text_generation import (
TextGenerationInput,
TextGenerationInputGenerateParameters,
TextGenerationInputGrammarType,
TextGenerationOutput,
TextGenerationOutputBestOfSequence,
TextGenerationOutputDetails,
TextGenerationOutputPrefillToken,
TextGenerationOutputToken,
TextGenerationStreamOutput,
TextGenerationStreamOutputStreamDetails,
TextGenerationStreamOutputToken,
)
from .text_to_audio import (
TextToAudioEarlyStoppingEnum,
TextToAudioGenerationParameters,
TextToAudioInput,
TextToAudioOutput,
TextToAudioParameters,
)
from .text_to_image import TextToImageInput, TextToImageOutput, TextToImageParameters, TextToImageTargetSize
from .text_to_speech import (
TextToSpeechEarlyStoppingEnum,
TextToSpeechGenerationParameters,
TextToSpeechInput,
TextToSpeechOutput,
TextToSpeechParameters,
)
from .token_classification import (
TokenClassificationInput,
TokenClassificationOutputElement,
TokenClassificationParameters,
)
from .translation import TranslationInput, TranslationOutput, TranslationParameters
from .video_classification import (
VideoClassificationInput,
VideoClassificationOutputElement,
VideoClassificationOutputTransform,
VideoClassificationParameters,
)
from .visual_question_answering import (
VisualQuestionAnsweringInput,
VisualQuestionAnsweringInputData,
VisualQuestionAnsweringOutputElement,
VisualQuestionAnsweringParameters,
)
from .zero_shot_classification import (
ZeroShotClassificationInput,
ZeroShotClassificationInputData,
ZeroShotClassificationOutputElement,
ZeroShotClassificationParameters,
)
from .zero_shot_image_classification import (
ZeroShotImageClassificationInput,
ZeroShotImageClassificationInputData,
ZeroShotImageClassificationOutputElement,
ZeroShotImageClassificationParameters,
)
from .zero_shot_object_detection import (
ZeroShotObjectDetectionBoundingBox,
ZeroShotObjectDetectionInput,
ZeroShotObjectDetectionInputData,
ZeroShotObjectDetectionOutputElement,
)

View File

@ -0,0 +1,46 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Literal, Optional
from .base import BaseInferenceType
AudioClassificationOutputTransform = Literal["sigmoid", "softmax", "none"]
@dataclass
class AudioClassificationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Audio Classification
"""
function_to_apply: Optional["AudioClassificationOutputTransform"] = None
"""The function to apply to the output."""
top_k: Optional[int] = None
"""When specified, limits the output to the top K most probable classes."""
@dataclass
class AudioClassificationInput(BaseInferenceType):
"""Inputs for Audio Classification inference"""
inputs: str
"""The input audio data as a base64-encoded string. If no `parameters` are provided, you can
also provide the audio data as a raw bytes payload.
"""
parameters: Optional[AudioClassificationParameters] = None
"""Additional inference parameters"""
@dataclass
class AudioClassificationOutputElement(BaseInferenceType):
"""Outputs for Audio Classification inference"""
label: str
"""The predicted class label."""
score: float
"""The corresponding probability."""

View File

@ -0,0 +1,31 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any
from .base import BaseInferenceType
@dataclass
class AudioToAudioInput(BaseInferenceType):
"""Inputs for Audio to Audio inference"""
inputs: Any
"""The input audio data"""
@dataclass
class AudioToAudioOutputElement(BaseInferenceType):
"""Outputs of inference for the Audio To Audio task
A generated audio file with its label.
"""
blob: Any
"""The generated audio file."""
content_type: str
"""The content type of audio file."""
label: str
"""The label of the audio file."""

View File

@ -0,0 +1,118 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import List, Literal, Optional, Union
from .base import BaseInferenceType
AutomaticSpeechRecognitionEarlyStoppingEnum = Literal["never"]
@dataclass
class AutomaticSpeechRecognitionGenerationParameters(BaseInferenceType):
"""Parametrization of the text generation process
Ad-hoc parametrization of the text generation process
"""
do_sample: Optional[bool] = None
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
early_stopping: Optional[Union[bool, "AutomaticSpeechRecognitionEarlyStoppingEnum"]] = None
"""Controls the stopping condition for beam-based methods."""
epsilon_cutoff: Optional[float] = None
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
"""
eta_cutoff: Optional[float] = None
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
float strictly between 0 and 1, a token is only considered if it is greater than either
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
term is intuitively the expected next token probability, scaled by sqrt(eta_cutoff). In
the paper, suggested values range from 3e-4 to 2e-3, depending on the size of the model.
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
for more details.
"""
max_length: Optional[int] = None
"""The maximum length (in tokens) of the generated text, including the input."""
max_new_tokens: Optional[int] = None
"""The maximum number of tokens to generate. Takes precedence over max_length."""
min_length: Optional[int] = None
"""The minimum length (in tokens) of the generated text, including the input."""
min_new_tokens: Optional[int] = None
"""The minimum number of tokens to generate. Takes precedence over min_length."""
num_beam_groups: Optional[int] = None
"""Number of groups to divide num_beams into in order to ensure diversity among different
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
"""
num_beams: Optional[int] = None
"""Number of beams to use for beam search."""
penalty_alpha: Optional[float] = None
"""The value balances the model confidence and the degeneration penalty in contrastive
search decoding.
"""
temperature: Optional[float] = None
"""The value used to modulate the next token probabilities."""
top_k: Optional[int] = None
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
top_p: Optional[float] = None
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
that add up to top_p or higher are kept for generation.
"""
typical_p: Optional[float] = None
"""Local typicality measures how similar the conditional probability of predicting a target
token next is to the expected conditional probability of predicting a random token next,
given the partial text already generated. If set to float < 1, the smallest set of the
most locally typical tokens with probabilities that add up to typical_p or higher are
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
"""
use_cache: Optional[bool] = None
"""Whether the model should use the past last key/values attentions to speed up decoding"""
@dataclass
class AutomaticSpeechRecognitionParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Automatic Speech Recognition
"""
generate: Optional[AutomaticSpeechRecognitionGenerationParameters] = None
"""Parametrization of the text generation process"""
return_timestamps: Optional[bool] = None
"""Whether to output corresponding timestamps with the generated text"""
@dataclass
class AutomaticSpeechRecognitionInput(BaseInferenceType):
"""Inputs for Automatic Speech Recognition inference"""
inputs: str
"""The input audio data as a base64-encoded string. If no `parameters` are provided, you can
also provide the audio data as a raw bytes payload.
"""
parameters: Optional[AutomaticSpeechRecognitionParameters] = None
"""Additional inference parameters"""
@dataclass
class AutomaticSpeechRecognitionOutputChunk(BaseInferenceType):
text: str
"""A chunk of text identified by the model"""
timestamps: List[float]
"""The start and end timestamps corresponding with the text"""
@dataclass
class AutomaticSpeechRecognitionOutput(BaseInferenceType):
"""Outputs of inference for the Automatic Speech Recognition task"""
text: str
"""The recognized text."""
chunks: Optional[List[AutomaticSpeechRecognitionOutputChunk]] = None
"""When returnTimestamps is enabled, chunks contains a list of audio chunks identified by
the model.
"""

View File

@ -0,0 +1,140 @@
# Copyright 2024 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains a base class for all inference types."""
import inspect
import json
from dataclasses import asdict, dataclass
from typing import Any, Dict, List, Type, TypeVar, Union, get_args
T = TypeVar("T", bound="BaseInferenceType")
@dataclass
class BaseInferenceType(dict):
"""Base class for all inference types.
Object is a dataclass and a dict for backward compatibility but plan is to remove the dict part in the future.
Handle parsing from dict, list and json strings in a permissive way to ensure future-compatibility (e.g. all fields
are made optional, and non-expected fields are added as dict attributes).
"""
@classmethod
def parse_obj_as_list(cls: Type[T], data: Union[bytes, str, List, Dict]) -> List[T]:
"""Alias to parse server response and return a single instance.
See `parse_obj` for more details.
"""
output = cls.parse_obj(data)
if not isinstance(output, list):
raise ValueError(f"Invalid input data for {cls}. Expected a list, but got {type(output)}.")
return output
@classmethod
def parse_obj_as_instance(cls: Type[T], data: Union[bytes, str, List, Dict]) -> T:
"""Alias to parse server response and return a single instance.
See `parse_obj` for more details.
"""
output = cls.parse_obj(data)
if isinstance(output, list):
raise ValueError(f"Invalid input data for {cls}. Expected a single instance, but got a list.")
return output
@classmethod
def parse_obj(cls: Type[T], data: Union[bytes, str, List, Dict]) -> Union[List[T], T]:
"""Parse server response as a dataclass or list of dataclasses.
To enable future-compatibility, we want to handle cases where the server return more fields than expected.
In such cases, we don't want to raise an error but still create the dataclass object. Remaining fields are
added as dict attributes.
"""
# Parse server response (from bytes)
if isinstance(data, bytes):
data = data.decode()
if isinstance(data, str):
data = json.loads(data)
# If a list, parse each item individually
if isinstance(data, List):
return [cls.parse_obj(d) for d in data] # type: ignore [misc]
# At this point, we expect a dict
if not isinstance(data, dict):
raise ValueError(f"Invalid data type: {type(data)}")
init_values = {}
other_values = {}
for key, value in data.items():
key = normalize_key(key)
if key in cls.__dataclass_fields__ and cls.__dataclass_fields__[key].init:
if isinstance(value, dict) or isinstance(value, list):
field_type = cls.__dataclass_fields__[key].type
# if `field_type` is a `BaseInferenceType`, parse it
if inspect.isclass(field_type) and issubclass(field_type, BaseInferenceType):
value = field_type.parse_obj(value)
# otherwise, recursively parse nested dataclasses (if possible)
# `get_args` returns handle Union and Optional for us
else:
expected_types = get_args(field_type)
for expected_type in expected_types:
if getattr(expected_type, "_name", None) == "List":
expected_type = get_args(expected_type)[
0
] # assume same type for all items in the list
if inspect.isclass(expected_type) and issubclass(expected_type, BaseInferenceType):
value = expected_type.parse_obj(value)
break
init_values[key] = value
else:
other_values[key] = value
# Make all missing fields default to None
# => ensure that dataclass initialization will never fail even if the server does not return all fields.
for key in cls.__dataclass_fields__:
if key not in init_values:
init_values[key] = None
# Initialize dataclass with expected values
item = cls(**init_values)
# Add remaining fields as dict attributes
item.update(other_values)
return item
def __post_init__(self):
self.update(asdict(self))
def __setitem__(self, __key: Any, __value: Any) -> None:
# Hacky way to keep dataclass values in sync when dict is updated
super().__setitem__(__key, __value)
if __key in self.__dataclass_fields__ and getattr(self, __key, None) != __value:
self.__setattr__(__key, __value)
return
def __setattr__(self, __name: str, __value: Any) -> None:
# Hacky way to keep dict values is sync when dataclass is updated
super().__setattr__(__name, __value)
if self.get(__name) != __value:
self[__name] = __value
return
def normalize_key(key: str) -> str:
# e.g "content-type" -> "content_type", "Accept" -> "accept"
return key.replace("-", "_").replace(" ", "_").lower()

View File

@ -0,0 +1,299 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, List, Literal, Optional, Union
from .base import BaseInferenceType
@dataclass
class ChatCompletionInputURL(BaseInferenceType):
url: str
ChatCompletionInputMessageChunkType = Literal["text", "image_url"]
@dataclass
class ChatCompletionInputMessageChunk(BaseInferenceType):
type: "ChatCompletionInputMessageChunkType"
image_url: Optional[ChatCompletionInputURL] = None
text: Optional[str] = None
@dataclass
class ChatCompletionInputMessage(BaseInferenceType):
content: Union[List[ChatCompletionInputMessageChunk], str]
role: str
name: Optional[str] = None
ChatCompletionInputGrammarTypeType = Literal["json", "regex"]
@dataclass
class ChatCompletionInputGrammarType(BaseInferenceType):
type: "ChatCompletionInputGrammarTypeType"
value: Any
"""A string that represents a [JSON Schema](https://json-schema.org/).
JSON Schema is a declarative language that allows to annotate JSON documents
with types and descriptions.
"""
@dataclass
class ChatCompletionInputStreamOptions(BaseInferenceType):
include_usage: bool
"""If set, an additional chunk will be streamed before the data: [DONE] message. The usage
field on this chunk shows the token usage statistics for the entire request, and the
choices field will always be an empty array. All other chunks will also include a usage
field, but with a null value.
"""
@dataclass
class ChatCompletionInputFunctionName(BaseInferenceType):
name: str
@dataclass
class ChatCompletionInputToolType(BaseInferenceType):
function: Optional[ChatCompletionInputFunctionName] = None
@dataclass
class ChatCompletionInputFunctionDefinition(BaseInferenceType):
arguments: Any
name: str
description: Optional[str] = None
@dataclass
class ToolElement(BaseInferenceType):
function: ChatCompletionInputFunctionDefinition
type: str
@dataclass
class ChatCompletionInput(BaseInferenceType):
"""Chat Completion Input.
Auto-generated from TGI specs.
For more details, check out
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
"""
messages: List[ChatCompletionInputMessage]
"""A list of messages comprising the conversation so far."""
frequency_penalty: Optional[float] = None
"""Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing
frequency in the text so far,
decreasing the model's likelihood to repeat the same line verbatim.
"""
logit_bias: Optional[List[float]] = None
"""UNUSED
Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON
object that maps tokens
(specified by their token ID in the tokenizer) to an associated bias value from -100 to
100. Mathematically,
the bias is added to the logits generated by the model prior to sampling. The exact
effect will vary per model,
but values between -1 and 1 should decrease or increase likelihood of selection; values
like -100 or 100 should
result in a ban or exclusive selection of the relevant token.
"""
logprobs: Optional[bool] = None
"""Whether to return log probabilities of the output tokens or not. If true, returns the log
probabilities of each
output token returned in the content of message.
"""
max_tokens: Optional[int] = None
"""The maximum number of tokens that can be generated in the chat completion."""
model: Optional[str] = None
"""[UNUSED] ID of the model to use. See the model endpoint compatibility table for details
on which models work with the Chat API.
"""
n: Optional[int] = None
"""UNUSED
How many chat completion choices to generate for each input message. Note that you will
be charged based on the
number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
"""
presence_penalty: Optional[float] = None
"""Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they
appear in the text so far,
increasing the model's likelihood to talk about new topics
"""
response_format: Optional[ChatCompletionInputGrammarType] = None
seed: Optional[int] = None
stop: Optional[List[str]] = None
"""Up to 4 sequences where the API will stop generating further tokens."""
stream: Optional[bool] = None
stream_options: Optional[ChatCompletionInputStreamOptions] = None
temperature: Optional[float] = None
"""What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the
output more random, while
lower values like 0.2 will make it more focused and deterministic.
We generally recommend altering this or `top_p` but not both.
"""
tool_choice: Optional[Union[ChatCompletionInputToolType, str]] = None
tool_prompt: Optional[str] = None
"""A prompt to be appended before the tools"""
tools: Optional[List[ToolElement]] = None
"""A list of tools the model may call. Currently, only functions are supported as a tool.
Use this to provide a list of
functions the model may generate JSON inputs for.
"""
top_logprobs: Optional[int] = None
"""An integer between 0 and 5 specifying the number of most likely tokens to return at each
token position, each with
an associated log probability. logprobs must be set to true if this parameter is used.
"""
top_p: Optional[float] = None
"""An alternative to sampling with temperature, called nucleus sampling, where the model
considers the results of the
tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10%
probability mass are considered.
"""
@dataclass
class ChatCompletionOutputTopLogprob(BaseInferenceType):
logprob: float
token: str
@dataclass
class ChatCompletionOutputLogprob(BaseInferenceType):
logprob: float
token: str
top_logprobs: List[ChatCompletionOutputTopLogprob]
@dataclass
class ChatCompletionOutputLogprobs(BaseInferenceType):
content: List[ChatCompletionOutputLogprob]
@dataclass
class ChatCompletionOutputFunctionDefinition(BaseInferenceType):
arguments: Any
name: str
description: Optional[str] = None
@dataclass
class ChatCompletionOutputToolCall(BaseInferenceType):
function: ChatCompletionOutputFunctionDefinition
id: str
type: str
@dataclass
class ChatCompletionOutputMessage(BaseInferenceType):
role: str
content: Optional[str] = None
tool_calls: Optional[List[ChatCompletionOutputToolCall]] = None
@dataclass
class ChatCompletionOutputComplete(BaseInferenceType):
finish_reason: str
index: int
message: ChatCompletionOutputMessage
logprobs: Optional[ChatCompletionOutputLogprobs] = None
@dataclass
class ChatCompletionOutputUsage(BaseInferenceType):
completion_tokens: int
prompt_tokens: int
total_tokens: int
@dataclass
class ChatCompletionOutput(BaseInferenceType):
"""Chat Completion Output.
Auto-generated from TGI specs.
For more details, check out
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
"""
choices: List[ChatCompletionOutputComplete]
created: int
id: str
model: str
system_fingerprint: str
usage: ChatCompletionOutputUsage
@dataclass
class ChatCompletionStreamOutputFunction(BaseInferenceType):
arguments: str
name: Optional[str] = None
@dataclass
class ChatCompletionStreamOutputDeltaToolCall(BaseInferenceType):
function: ChatCompletionStreamOutputFunction
id: str
index: int
type: str
@dataclass
class ChatCompletionStreamOutputDelta(BaseInferenceType):
role: str
content: Optional[str] = None
tool_calls: Optional[ChatCompletionStreamOutputDeltaToolCall] = None
@dataclass
class ChatCompletionStreamOutputTopLogprob(BaseInferenceType):
logprob: float
token: str
@dataclass
class ChatCompletionStreamOutputLogprob(BaseInferenceType):
logprob: float
token: str
top_logprobs: List[ChatCompletionStreamOutputTopLogprob]
@dataclass
class ChatCompletionStreamOutputLogprobs(BaseInferenceType):
content: List[ChatCompletionStreamOutputLogprob]
@dataclass
class ChatCompletionStreamOutputChoice(BaseInferenceType):
delta: ChatCompletionStreamOutputDelta
index: int
finish_reason: Optional[str] = None
logprobs: Optional[ChatCompletionStreamOutputLogprobs] = None
@dataclass
class ChatCompletionStreamOutputUsage(BaseInferenceType):
completion_tokens: int
prompt_tokens: int
total_tokens: int
@dataclass
class ChatCompletionStreamOutput(BaseInferenceType):
"""Chat Completion Stream Output.
Auto-generated from TGI specs.
For more details, check out
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
"""
choices: List[ChatCompletionStreamOutputChoice]
created: int
id: str
model: str
system_fingerprint: str
usage: Optional[ChatCompletionStreamOutputUsage] = None

View File

@ -0,0 +1,29 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Dict, Optional
from .base import BaseInferenceType
@dataclass
class DepthEstimationInput(BaseInferenceType):
"""Inputs for Depth Estimation inference"""
inputs: Any
"""The input image data"""
parameters: Optional[Dict[str, Any]] = None
"""Additional inference parameters"""
@dataclass
class DepthEstimationOutput(BaseInferenceType):
"""Outputs of inference for the Depth Estimation task"""
depth: Any
"""The predicted depth as an image"""
predicted_depth: Any
"""The predicted depth as a tensor"""

View File

@ -0,0 +1,85 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, List, Optional, Union
from .base import BaseInferenceType
@dataclass
class DocumentQuestionAnsweringInputData(BaseInferenceType):
"""One (document, question) pair to answer"""
image: Any
"""The image on which the question is asked"""
question: str
"""A question to ask of the document"""
@dataclass
class DocumentQuestionAnsweringParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Document Question Answering
"""
doc_stride: Optional[int] = None
"""If the words in the document are too long to fit with the question for the model, it will
be split in several chunks with some overlap. This argument controls the size of that
overlap.
"""
handle_impossible_answer: Optional[bool] = None
"""Whether to accept impossible as an answer"""
lang: Optional[str] = None
"""Language to use while running OCR. Defaults to english."""
max_answer_len: Optional[int] = None
"""The maximum length of predicted answers (e.g., only answers with a shorter length are
considered).
"""
max_question_len: Optional[int] = None
"""The maximum length of the question after tokenization. It will be truncated if needed."""
max_seq_len: Optional[int] = None
"""The maximum length of the total sentence (context + question) in tokens of each chunk
passed to the model. The context will be split in several chunks (using doc_stride as
overlap) if needed.
"""
top_k: Optional[int] = None
"""The number of answers to return (will be chosen by order of likelihood). Can return less
than top_k answers if there are not enough options available within the context.
"""
word_boxes: Optional[List[Union[List[float], str]]] = None
"""A list of words and bounding boxes (normalized 0->1000). If provided, the inference will
skip the OCR step and use the provided bounding boxes instead.
"""
@dataclass
class DocumentQuestionAnsweringInput(BaseInferenceType):
"""Inputs for Document Question Answering inference"""
inputs: DocumentQuestionAnsweringInputData
"""One (document, question) pair to answer"""
parameters: Optional[DocumentQuestionAnsweringParameters] = None
"""Additional inference parameters"""
@dataclass
class DocumentQuestionAnsweringOutputElement(BaseInferenceType):
"""Outputs of inference for the Document Question Answering task"""
answer: str
"""The answer to the question."""
end: int
"""The end word index of the answer (in the OCRd version of the input or provided word
boxes).
"""
score: float
"""The probability associated to the answer."""
start: int
"""The start word index of the answer (in the OCRd version of the input or provided word
boxes).
"""
words: List[int]
"""The index of each word/box pair that is in the answer"""

View File

@ -0,0 +1,37 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Literal, Optional
from .base import BaseInferenceType
FeatureExtractionInputTruncationDirection = Literal["Left", "Right"]
@dataclass
class FeatureExtractionInput(BaseInferenceType):
"""Feature Extraction Input.
Auto-generated from TEI specs.
For more details, check out
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tei-import.ts.
"""
inputs: str
"""The text to embed."""
normalize: Optional[bool] = None
prompt_name: Optional[str] = None
"""The name of the prompt that should be used by for encoding. If not set, no prompt
will be applied.
Must be a key in the `Sentence Transformers` configuration `prompts` dictionary.
For example if ``prompt_name`` is "query" and the ``prompts`` is {"query": "query: ",
...},
then the sentence "What is the capital of France?" will be encoded as
"query: What is the capital of France?" because the prompt text will be prepended before
any text to encode.
"""
truncate: Optional[bool] = None
truncation_direction: Optional["FeatureExtractionInputTruncationDirection"] = None

View File

@ -0,0 +1,50 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, List, Optional
from .base import BaseInferenceType
@dataclass
class FillMaskParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Fill Mask
"""
targets: Optional[List[str]] = None
"""When passed, the model will limit the scores to the passed targets instead of looking up
in the whole vocabulary. If the provided targets are not in the model vocab, they will be
tokenized and the first resulting token will be used (with a warning, and that might be
slower).
"""
top_k: Optional[int] = None
"""When passed, overrides the number of predictions to return."""
@dataclass
class FillMaskInput(BaseInferenceType):
"""Inputs for Fill Mask inference"""
inputs: str
"""The text with masked tokens"""
parameters: Optional[FillMaskParameters] = None
"""Additional inference parameters"""
@dataclass
class FillMaskOutputElement(BaseInferenceType):
"""Outputs of inference for the Fill Mask task"""
score: float
"""The corresponding probability"""
sequence: str
"""The corresponding input with the mask token prediction."""
token: int
"""The predicted token id (to replace the masked one)."""
token_str: Any
fill_mask_output_token_str: Optional[str] = None
"""The predicted token (to replace the masked one)."""

View File

@ -0,0 +1,46 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Literal, Optional
from .base import BaseInferenceType
ImageClassificationOutputTransform = Literal["sigmoid", "softmax", "none"]
@dataclass
class ImageClassificationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Image Classification
"""
function_to_apply: Optional["ImageClassificationOutputTransform"] = None
"""The function to apply to the output."""
top_k: Optional[int] = None
"""When specified, limits the output to the top K most probable classes."""
@dataclass
class ImageClassificationInput(BaseInferenceType):
"""Inputs for Image Classification inference"""
inputs: str
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
also provide the image data as a raw bytes payload.
"""
parameters: Optional[ImageClassificationParameters] = None
"""Additional inference parameters"""
@dataclass
class ImageClassificationOutputElement(BaseInferenceType):
"""Outputs of inference for the Image Classification task"""
label: str
"""The predicted class label."""
score: float
"""The corresponding probability."""

View File

@ -0,0 +1,54 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Literal, Optional
from .base import BaseInferenceType
ImageSegmentationSubtask = Literal["instance", "panoptic", "semantic"]
@dataclass
class ImageSegmentationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Image Segmentation
"""
mask_threshold: Optional[float] = None
"""Threshold to use when turning the predicted masks into binary values."""
overlap_mask_area_threshold: Optional[float] = None
"""Mask overlap threshold to eliminate small, disconnected segments."""
subtask: Optional["ImageSegmentationSubtask"] = None
"""Segmentation task to be performed, depending on model capabilities."""
threshold: Optional[float] = None
"""Probability threshold to filter out predicted masks."""
@dataclass
class ImageSegmentationInput(BaseInferenceType):
"""Inputs for Image Segmentation inference"""
inputs: str
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
also provide the image data as a raw bytes payload.
"""
parameters: Optional[ImageSegmentationParameters] = None
"""Additional inference parameters"""
@dataclass
class ImageSegmentationOutputElement(BaseInferenceType):
"""Outputs of inference for the Image Segmentation task
A predicted mask / segment
"""
label: str
"""The label of the predicted segment."""
mask: str
"""The corresponding mask as a black-and-white image (base64-encoded)."""
score: Optional[float] = None
"""The score or confidence degree the model has."""

View File

@ -0,0 +1,57 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, List, Optional
from .base import BaseInferenceType
@dataclass
class ImageToImageTargetSize(BaseInferenceType):
"""The size in pixel of the output image."""
height: int
width: int
@dataclass
class ImageToImageParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Image To Image
"""
guidance_scale: Optional[float] = None
"""For diffusion models. A higher guidance scale value encourages the model to generate
images closely linked to the text prompt at the expense of lower image quality.
"""
negative_prompt: Optional[List[str]] = None
"""One or several prompt to guide what NOT to include in image generation."""
num_inference_steps: Optional[int] = None
"""For diffusion models. The number of denoising steps. More denoising steps usually lead to
a higher quality image at the expense of slower inference.
"""
target_size: Optional[ImageToImageTargetSize] = None
"""The size in pixel of the output image."""
@dataclass
class ImageToImageInput(BaseInferenceType):
"""Inputs for Image To Image inference"""
inputs: str
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
also provide the image data as a raw bytes payload.
"""
parameters: Optional[ImageToImageParameters] = None
"""Additional inference parameters"""
@dataclass
class ImageToImageOutput(BaseInferenceType):
"""Outputs of inference for the Image To Image task"""
image: Any
"""The output image returned as raw bytes in the payload."""

View File

@ -0,0 +1,105 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Literal, Optional, Union
from .base import BaseInferenceType
ImageToTextEarlyStoppingEnum = Literal["never"]
@dataclass
class ImageToTextGenerationParameters(BaseInferenceType):
"""Parametrization of the text generation process
Ad-hoc parametrization of the text generation process
"""
do_sample: Optional[bool] = None
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
early_stopping: Optional[Union[bool, "ImageToTextEarlyStoppingEnum"]] = None
"""Controls the stopping condition for beam-based methods."""
epsilon_cutoff: Optional[float] = None
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
"""
eta_cutoff: Optional[float] = None
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
float strictly between 0 and 1, a token is only considered if it is greater than either
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
term is intuitively the expected next token probability, scaled by sqrt(eta_cutoff). In
the paper, suggested values range from 3e-4 to 2e-3, depending on the size of the model.
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
for more details.
"""
max_length: Optional[int] = None
"""The maximum length (in tokens) of the generated text, including the input."""
max_new_tokens: Optional[int] = None
"""The maximum number of tokens to generate. Takes precedence over max_length."""
min_length: Optional[int] = None
"""The minimum length (in tokens) of the generated text, including the input."""
min_new_tokens: Optional[int] = None
"""The minimum number of tokens to generate. Takes precedence over min_length."""
num_beam_groups: Optional[int] = None
"""Number of groups to divide num_beams into in order to ensure diversity among different
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
"""
num_beams: Optional[int] = None
"""Number of beams to use for beam search."""
penalty_alpha: Optional[float] = None
"""The value balances the model confidence and the degeneration penalty in contrastive
search decoding.
"""
temperature: Optional[float] = None
"""The value used to modulate the next token probabilities."""
top_k: Optional[int] = None
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
top_p: Optional[float] = None
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
that add up to top_p or higher are kept for generation.
"""
typical_p: Optional[float] = None
"""Local typicality measures how similar the conditional probability of predicting a target
token next is to the expected conditional probability of predicting a random token next,
given the partial text already generated. If set to float < 1, the smallest set of the
most locally typical tokens with probabilities that add up to typical_p or higher are
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
"""
use_cache: Optional[bool] = None
"""Whether the model should use the past last key/values attentions to speed up decoding"""
@dataclass
class ImageToTextParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Image To Text
"""
generate: Optional[ImageToTextGenerationParameters] = None
"""Parametrization of the text generation process"""
max_new_tokens: Optional[int] = None
"""The amount of maximum tokens to generate."""
@dataclass
class ImageToTextInput(BaseInferenceType):
"""Inputs for Image To Text inference"""
inputs: Any
"""The input image data"""
parameters: Optional[ImageToTextParameters] = None
"""Additional inference parameters"""
@dataclass
class ImageToTextOutput(BaseInferenceType):
"""Outputs of inference for the Image To Text task"""
generated_text: Any
image_to_text_output_generated_text: Optional[str] = None
"""The generated text."""

View File

@ -0,0 +1,61 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Optional
from .base import BaseInferenceType
@dataclass
class ObjectDetectionParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Object Detection
"""
threshold: Optional[float] = None
"""The probability necessary to make a prediction."""
@dataclass
class ObjectDetectionInput(BaseInferenceType):
"""Inputs for Object Detection inference"""
inputs: str
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
also provide the image data as a raw bytes payload.
"""
parameters: Optional[ObjectDetectionParameters] = None
"""Additional inference parameters"""
@dataclass
class ObjectDetectionBoundingBox(BaseInferenceType):
"""The predicted bounding box. Coordinates are relative to the top left corner of the input
image.
"""
xmax: int
"""The x-coordinate of the bottom-right corner of the bounding box."""
xmin: int
"""The x-coordinate of the top-left corner of the bounding box."""
ymax: int
"""The y-coordinate of the bottom-right corner of the bounding box."""
ymin: int
"""The y-coordinate of the top-left corner of the bounding box."""
@dataclass
class ObjectDetectionOutputElement(BaseInferenceType):
"""Outputs of inference for the Object Detection task"""
box: ObjectDetectionBoundingBox
"""The predicted bounding box. Coordinates are relative to the top left corner of the input
image.
"""
label: str
"""The predicted label for the bounding box."""
score: float
"""The associated score / probability."""

View File

@ -0,0 +1,77 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Optional
from .base import BaseInferenceType
@dataclass
class QuestionAnsweringInputData(BaseInferenceType):
"""One (context, question) pair to answer"""
context: str
"""The context to be used for answering the question"""
question: str
"""The question to be answered"""
@dataclass
class QuestionAnsweringParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Question Answering
"""
align_to_words: Optional[bool] = None
"""Attempts to align the answer to real words. Improves quality on space separated
languages. Might hurt on non-space-separated languages (like Japanese or Chinese)
"""
doc_stride: Optional[int] = None
"""If the context is too long to fit with the question for the model, it will be split in
several chunks with some overlap. This argument controls the size of that overlap.
"""
handle_impossible_answer: Optional[bool] = None
"""Whether to accept impossible as an answer."""
max_answer_len: Optional[int] = None
"""The maximum length of predicted answers (e.g., only answers with a shorter length are
considered).
"""
max_question_len: Optional[int] = None
"""The maximum length of the question after tokenization. It will be truncated if needed."""
max_seq_len: Optional[int] = None
"""The maximum length of the total sentence (context + question) in tokens of each chunk
passed to the model. The context will be split in several chunks (using docStride as
overlap) if needed.
"""
top_k: Optional[int] = None
"""The number of answers to return (will be chosen by order of likelihood). Note that we
return less than topk answers if there are not enough options available within the
context.
"""
@dataclass
class QuestionAnsweringInput(BaseInferenceType):
"""Inputs for Question Answering inference"""
inputs: QuestionAnsweringInputData
"""One (context, question) pair to answer"""
parameters: Optional[QuestionAnsweringParameters] = None
"""Additional inference parameters"""
@dataclass
class QuestionAnsweringOutputElement(BaseInferenceType):
"""Outputs of inference for the Question Answering task"""
answer: str
"""The answer to the question."""
end: int
"""The character position in the input where the answer ends."""
score: float
"""The probability associated to the answer."""
start: int
"""The character position in the input where the answer begins."""

View File

@ -0,0 +1,28 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Dict, List, Optional
from .base import BaseInferenceType
@dataclass
class SentenceSimilarityInputData(BaseInferenceType):
sentences: List[str]
"""A list of strings which will be compared against the source_sentence."""
source_sentence: str
"""The string that you wish to compare the other strings with. This can be a phrase,
sentence, or longer passage, depending on the model being used.
"""
@dataclass
class SentenceSimilarityInput(BaseInferenceType):
"""Inputs for Sentence similarity inference"""
inputs: SentenceSimilarityInputData
parameters: Optional[Dict[str, Any]] = None
"""Additional inference parameters"""

View File

@ -0,0 +1,44 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Dict, Literal, Optional
from .base import BaseInferenceType
SummarizationTruncationStrategy = Literal["do_not_truncate", "longest_first", "only_first", "only_second"]
@dataclass
class SummarizationParameters(BaseInferenceType):
"""Additional inference parameters.
Additional inference parameters for summarization.
"""
clean_up_tokenization_spaces: Optional[bool] = None
"""Whether to clean up the potential extra spaces in the text output."""
generate_parameters: Optional[Dict[str, Any]] = None
"""Additional parametrization of the text generation algorithm."""
truncation: Optional["SummarizationTruncationStrategy"] = None
"""The truncation strategy to use."""
@dataclass
class SummarizationInput(BaseInferenceType):
"""Inputs for Summarization inference"""
inputs: str
"""The input text to summarize."""
parameters: Optional[SummarizationParameters] = None
"""Additional inference parameters."""
@dataclass
class SummarizationOutput(BaseInferenceType):
"""Outputs of inference for the Summarization task"""
summary_text: str
"""The summarized text."""

View File

@ -0,0 +1,45 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Dict, List, Optional
from .base import BaseInferenceType
@dataclass
class TableQuestionAnsweringInputData(BaseInferenceType):
"""One (table, question) pair to answer"""
question: str
"""The question to be answered about the table"""
table: Dict[str, List[str]]
"""The table to serve as context for the questions"""
@dataclass
class TableQuestionAnsweringInput(BaseInferenceType):
"""Inputs for Table Question Answering inference"""
inputs: TableQuestionAnsweringInputData
"""One (table, question) pair to answer"""
parameters: Optional[Dict[str, Any]] = None
"""Additional inference parameters"""
@dataclass
class TableQuestionAnsweringOutputElement(BaseInferenceType):
"""Outputs of inference for the Table Question Answering task"""
answer: str
"""The answer of the question given the table. If there is an aggregator, the answer will be
preceded by `AGGREGATOR >`.
"""
cells: List[str]
"""List of strings made up of the answer cell values."""
coordinates: List[List[int]]
"""Coordinates of the cells of the answers."""
aggregator: Optional[str] = None
"""If the model has an aggregator, this returns the aggregator."""

View File

@ -0,0 +1,45 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Dict, Literal, Optional
from .base import BaseInferenceType
Text2TextGenerationTruncationStrategy = Literal["do_not_truncate", "longest_first", "only_first", "only_second"]
@dataclass
class Text2TextGenerationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Text2text Generation
"""
clean_up_tokenization_spaces: Optional[bool] = None
"""Whether to clean up the potential extra spaces in the text output."""
generate_parameters: Optional[Dict[str, Any]] = None
"""Additional parametrization of the text generation algorithm"""
truncation: Optional["Text2TextGenerationTruncationStrategy"] = None
"""The truncation strategy to use"""
@dataclass
class Text2TextGenerationInput(BaseInferenceType):
"""Inputs for Text2text Generation inference"""
inputs: str
"""The input text data"""
parameters: Optional[Text2TextGenerationParameters] = None
"""Additional inference parameters"""
@dataclass
class Text2TextGenerationOutput(BaseInferenceType):
"""Outputs of inference for the Text2text Generation task"""
generated_text: Any
text2_text_generation_output_generated_text: Optional[str] = None
"""The generated text."""

View File

@ -0,0 +1,48 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Literal, Optional
from .base import BaseInferenceType
TextClassificationOutputTransform = Literal["sigmoid", "softmax", "none"]
@dataclass
class TextClassificationParameters(BaseInferenceType):
"""
Additional inference parameters for Text Classification.
"""
function_to_apply: Optional["TextClassificationOutputTransform"] = None
"""
The function to apply to the output.
"""
top_k: Optional[int] = None
"""
When specified, limits the output to the top K most probable classes.
"""
@dataclass
class TextClassificationInput(BaseInferenceType):
"""Inputs for Text Classification inference"""
inputs: str
"""The text to classify"""
parameters: Optional[TextClassificationParameters] = None
"""Additional inference parameters"""
@dataclass
class TextClassificationOutputElement(BaseInferenceType):
"""Outputs of inference for the Text Classification task"""
label: str
"""The predicted class label."""
score: float
"""The corresponding probability."""

View File

@ -0,0 +1,169 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, List, Literal, Optional
from .base import BaseInferenceType
TypeEnum = Literal["json", "regex"]
@dataclass
class TextGenerationInputGrammarType(BaseInferenceType):
type: "TypeEnum"
value: Any
"""A string that represents a [JSON Schema](https://json-schema.org/).
JSON Schema is a declarative language that allows to annotate JSON documents
with types and descriptions.
"""
@dataclass
class TextGenerationInputGenerateParameters(BaseInferenceType):
adapter_id: Optional[str] = None
"""Lora adapter id"""
best_of: Optional[int] = None
"""Generate best_of sequences and return the one if the highest token logprobs."""
decoder_input_details: Optional[bool] = None
"""Whether to return decoder input token logprobs and ids."""
details: Optional[bool] = None
"""Whether to return generation details."""
do_sample: Optional[bool] = None
"""Activate logits sampling."""
frequency_penalty: Optional[float] = None
"""The parameter for frequency penalty. 1.0 means no penalty
Penalize new tokens based on their existing frequency in the text so far,
decreasing the model's likelihood to repeat the same line verbatim.
"""
grammar: Optional[TextGenerationInputGrammarType] = None
max_new_tokens: Optional[int] = None
"""Maximum number of tokens to generate."""
repetition_penalty: Optional[float] = None
"""The parameter for repetition penalty. 1.0 means no penalty.
See [this paper](https://arxiv.org/pdf/1909.05858.pdf) for more details.
"""
return_full_text: Optional[bool] = None
"""Whether to prepend the prompt to the generated text"""
seed: Optional[int] = None
"""Random sampling seed."""
stop: Optional[List[str]] = None
"""Stop generating tokens if a member of `stop` is generated."""
temperature: Optional[float] = None
"""The value used to module the logits distribution."""
top_k: Optional[int] = None
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
top_n_tokens: Optional[int] = None
"""The number of highest probability vocabulary tokens to keep for top-n-filtering."""
top_p: Optional[float] = None
"""Top-p value for nucleus sampling."""
truncate: Optional[int] = None
"""Truncate inputs tokens to the given size."""
typical_p: Optional[float] = None
"""Typical Decoding mass
See [Typical Decoding for Natural Language Generation](https://arxiv.org/abs/2202.00666)
for more information.
"""
watermark: Optional[bool] = None
"""Watermarking with [A Watermark for Large Language
Models](https://arxiv.org/abs/2301.10226).
"""
@dataclass
class TextGenerationInput(BaseInferenceType):
"""Text Generation Input.
Auto-generated from TGI specs.
For more details, check out
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
"""
inputs: str
parameters: Optional[TextGenerationInputGenerateParameters] = None
stream: Optional[bool] = None
TextGenerationOutputFinishReason = Literal["length", "eos_token", "stop_sequence"]
@dataclass
class TextGenerationOutputPrefillToken(BaseInferenceType):
id: int
logprob: float
text: str
@dataclass
class TextGenerationOutputToken(BaseInferenceType):
id: int
logprob: float
special: bool
text: str
@dataclass
class TextGenerationOutputBestOfSequence(BaseInferenceType):
finish_reason: "TextGenerationOutputFinishReason"
generated_text: str
generated_tokens: int
prefill: List[TextGenerationOutputPrefillToken]
tokens: List[TextGenerationOutputToken]
seed: Optional[int] = None
top_tokens: Optional[List[List[TextGenerationOutputToken]]] = None
@dataclass
class TextGenerationOutputDetails(BaseInferenceType):
finish_reason: "TextGenerationOutputFinishReason"
generated_tokens: int
prefill: List[TextGenerationOutputPrefillToken]
tokens: List[TextGenerationOutputToken]
best_of_sequences: Optional[List[TextGenerationOutputBestOfSequence]] = None
seed: Optional[int] = None
top_tokens: Optional[List[List[TextGenerationOutputToken]]] = None
@dataclass
class TextGenerationOutput(BaseInferenceType):
"""Text Generation Output.
Auto-generated from TGI specs.
For more details, check out
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
"""
generated_text: str
details: Optional[TextGenerationOutputDetails] = None
@dataclass
class TextGenerationStreamOutputStreamDetails(BaseInferenceType):
finish_reason: "TextGenerationOutputFinishReason"
generated_tokens: int
input_length: int
seed: Optional[int] = None
@dataclass
class TextGenerationStreamOutputToken(BaseInferenceType):
id: int
logprob: float
special: bool
text: str
@dataclass
class TextGenerationStreamOutput(BaseInferenceType):
"""Text Generation Stream Output.
Auto-generated from TGI specs.
For more details, check out
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
"""
index: int
token: TextGenerationStreamOutputToken
details: Optional[TextGenerationStreamOutputStreamDetails] = None
generated_text: Optional[str] = None
top_tokens: Optional[List[TextGenerationStreamOutputToken]] = None

View File

@ -0,0 +1,105 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Literal, Optional, Union
from .base import BaseInferenceType
TextToAudioEarlyStoppingEnum = Literal["never"]
@dataclass
class TextToAudioGenerationParameters(BaseInferenceType):
"""Parametrization of the text generation process
Ad-hoc parametrization of the text generation process
"""
do_sample: Optional[bool] = None
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
early_stopping: Optional[Union[bool, "TextToAudioEarlyStoppingEnum"]] = None
"""Controls the stopping condition for beam-based methods."""
epsilon_cutoff: Optional[float] = None
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
"""
eta_cutoff: Optional[float] = None
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
float strictly between 0 and 1, a token is only considered if it is greater than either
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
term is intuitively the expected next token probability, scaled by sqrt(eta_cutoff). In
the paper, suggested values range from 3e-4 to 2e-3, depending on the size of the model.
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
for more details.
"""
max_length: Optional[int] = None
"""The maximum length (in tokens) of the generated text, including the input."""
max_new_tokens: Optional[int] = None
"""The maximum number of tokens to generate. Takes precedence over maxLength."""
min_length: Optional[int] = None
"""The minimum length (in tokens) of the generated text, including the input."""
min_new_tokens: Optional[int] = None
"""The minimum number of tokens to generate. Takes precedence over maxLength."""
num_beam_groups: Optional[int] = None
"""Number of groups to divide num_beams into in order to ensure diversity among different
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
"""
num_beams: Optional[int] = None
"""Number of beams to use for beam search."""
penalty_alpha: Optional[float] = None
"""The value balances the model confidence and the degeneration penalty in contrastive
search decoding.
"""
temperature: Optional[float] = None
"""The value used to modulate the next token probabilities."""
top_k: Optional[int] = None
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
top_p: Optional[float] = None
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
that add up to top_p or higher are kept for generation.
"""
typical_p: Optional[float] = None
"""Local typicality measures how similar the conditional probability of predicting a target
token next is to the expected conditional probability of predicting a random token next,
given the partial text already generated. If set to float < 1, the smallest set of the
most locally typical tokens with probabilities that add up to typical_p or higher are
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
"""
use_cache: Optional[bool] = None
"""Whether the model should use the past last key/values attentions to speed up decoding"""
@dataclass
class TextToAudioParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Text To Audio
"""
generate: Optional[TextToAudioGenerationParameters] = None
"""Parametrization of the text generation process"""
@dataclass
class TextToAudioInput(BaseInferenceType):
"""Inputs for Text To Audio inference"""
inputs: str
"""The input text data"""
parameters: Optional[TextToAudioParameters] = None
"""Additional inference parameters"""
@dataclass
class TextToAudioOutput(BaseInferenceType):
"""Outputs of inference for the Text To Audio task"""
audio: Any
"""The generated audio waveform."""
sampling_rate: Any
text_to_audio_output_sampling_rate: Optional[float] = None
"""The sampling rate of the generated audio waveform."""

View File

@ -0,0 +1,59 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, List, Optional
from .base import BaseInferenceType
@dataclass
class TextToImageTargetSize(BaseInferenceType):
"""The size in pixel of the output image"""
height: int
width: int
@dataclass
class TextToImageParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Text To Image
"""
guidance_scale: Optional[float] = None
"""A higher guidance scale value encourages the model to generate images closely linked to
the text prompt, but values too high may cause saturation and other artifacts.
"""
negative_prompt: Optional[List[str]] = None
"""One or several prompt to guide what NOT to include in image generation."""
num_inference_steps: Optional[int] = None
"""The number of denoising steps. More denoising steps usually lead to a higher quality
image at the expense of slower inference.
"""
scheduler: Optional[str] = None
"""Override the scheduler with a compatible one."""
seed: Optional[int] = None
"""Seed for the random number generator."""
target_size: Optional[TextToImageTargetSize] = None
"""The size in pixel of the output image"""
@dataclass
class TextToImageInput(BaseInferenceType):
"""Inputs for Text To Image inference"""
inputs: str
"""The input text data (sometimes called "prompt")"""
parameters: Optional[TextToImageParameters] = None
"""Additional inference parameters"""
@dataclass
class TextToImageOutput(BaseInferenceType):
"""Outputs of inference for the Text To Image task"""
image: Any
"""The generated image returned as raw bytes in the payload."""

View File

@ -0,0 +1,107 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Literal, Optional, Union
from .base import BaseInferenceType
TextToSpeechEarlyStoppingEnum = Literal["never"]
@dataclass
class TextToSpeechGenerationParameters(BaseInferenceType):
"""Parametrization of the text generation process
Ad-hoc parametrization of the text generation process
"""
do_sample: Optional[bool] = None
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
early_stopping: Optional[Union[bool, "TextToSpeechEarlyStoppingEnum"]] = None
"""Controls the stopping condition for beam-based methods."""
epsilon_cutoff: Optional[float] = None
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
"""
eta_cutoff: Optional[float] = None
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
float strictly between 0 and 1, a token is only considered if it is greater than either
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
term is intuitively the expected next token probability, scaled by sqrt(eta_cutoff). In
the paper, suggested values range from 3e-4 to 2e-3, depending on the size of the model.
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
for more details.
"""
max_length: Optional[int] = None
"""The maximum length (in tokens) of the generated text, including the input."""
max_new_tokens: Optional[int] = None
"""The maximum number of tokens to generate. Takes precedence over maxLength."""
min_length: Optional[int] = None
"""The minimum length (in tokens) of the generated text, including the input."""
min_new_tokens: Optional[int] = None
"""The minimum number of tokens to generate. Takes precedence over maxLength."""
num_beam_groups: Optional[int] = None
"""Number of groups to divide num_beams into in order to ensure diversity among different
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
"""
num_beams: Optional[int] = None
"""Number of beams to use for beam search."""
penalty_alpha: Optional[float] = None
"""The value balances the model confidence and the degeneration penalty in contrastive
search decoding.
"""
temperature: Optional[float] = None
"""The value used to modulate the next token probabilities."""
top_k: Optional[int] = None
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
top_p: Optional[float] = None
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
that add up to top_p or higher are kept for generation.
"""
typical_p: Optional[float] = None
"""Local typicality measures how similar the conditional probability of predicting a target
token next is to the expected conditional probability of predicting a random token next,
given the partial text already generated. If set to float < 1, the smallest set of the
most locally typical tokens with probabilities that add up to typical_p or higher are
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
"""
use_cache: Optional[bool] = None
"""Whether the model should use the past last key/values attentions to speed up decoding"""
@dataclass
class TextToSpeechParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Text To Speech
"""
generate: Optional[TextToSpeechGenerationParameters] = None
"""Parametrization of the text generation process"""
@dataclass
class TextToSpeechInput(BaseInferenceType):
"""Inputs for Text To Speech inference"""
inputs: str
"""The input text data"""
parameters: Optional[TextToSpeechParameters] = None
"""Additional inference parameters"""
@dataclass
class TextToSpeechOutput(BaseInferenceType):
"""Outputs for Text to Speech inference
Outputs of inference for the Text To Audio task
"""
audio: Any
"""The generated audio waveform."""
sampling_rate: Any
text_to_speech_output_sampling_rate: Optional[float] = None
"""The sampling rate of the generated audio waveform."""

View File

@ -0,0 +1,53 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, List, Literal, Optional
from .base import BaseInferenceType
TokenClassificationAggregationStrategy = Literal["none", "simple", "first", "average", "max"]
@dataclass
class TokenClassificationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Token Classification
"""
aggregation_strategy: Optional["TokenClassificationAggregationStrategy"] = None
"""The strategy used to fuse tokens based on model predictions"""
ignore_labels: Optional[List[str]] = None
"""A list of labels to ignore"""
stride: Optional[int] = None
"""The number of overlapping tokens between chunks when splitting the input text."""
@dataclass
class TokenClassificationInput(BaseInferenceType):
"""Inputs for Token Classification inference"""
inputs: str
"""The input text data"""
parameters: Optional[TokenClassificationParameters] = None
"""Additional inference parameters"""
@dataclass
class TokenClassificationOutputElement(BaseInferenceType):
"""Outputs of inference for the Token Classification task"""
label: Any
score: float
"""The associated score / probability"""
end: Optional[int] = None
"""The character position in the input where this group ends."""
entity_group: Optional[str] = None
"""The predicted label for that group of tokens"""
start: Optional[int] = None
"""The character position in the input where this group begins."""
word: Optional[str] = None
"""The corresponding text"""

View File

@ -0,0 +1,52 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Dict, Literal, Optional
from .base import BaseInferenceType
TranslationTruncationStrategy = Literal["do_not_truncate", "longest_first", "only_first", "only_second"]
@dataclass
class TranslationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Translation
"""
clean_up_tokenization_spaces: Optional[bool] = None
"""Whether to clean up the potential extra spaces in the text output."""
generate_parameters: Optional[Dict[str, Any]] = None
"""Additional parametrization of the text generation algorithm."""
src_lang: Optional[str] = None
"""The source language of the text. Required for models that can translate from multiple
languages.
"""
tgt_lang: Optional[str] = None
"""Target language to translate to. Required for models that can translate to multiple
languages.
"""
truncation: Optional["TranslationTruncationStrategy"] = None
"""The truncation strategy to use."""
@dataclass
class TranslationInput(BaseInferenceType):
"""Inputs for Translation inference"""
inputs: str
"""The text to translate."""
parameters: Optional[TranslationParameters] = None
"""Additional inference parameters"""
@dataclass
class TranslationOutput(BaseInferenceType):
"""Outputs of inference for the Translation task"""
translation_text: str
"""The translated text."""

View File

@ -0,0 +1,47 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Literal, Optional
from .base import BaseInferenceType
VideoClassificationOutputTransform = Literal["sigmoid", "softmax", "none"]
@dataclass
class VideoClassificationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Video Classification
"""
frame_sampling_rate: Optional[int] = None
"""The sampling rate used to select frames from the video."""
function_to_apply: Optional["VideoClassificationOutputTransform"] = None
num_frames: Optional[int] = None
"""The number of sampled frames to consider for classification."""
top_k: Optional[int] = None
"""When specified, limits the output to the top K most probable classes."""
@dataclass
class VideoClassificationInput(BaseInferenceType):
"""Inputs for Video Classification inference"""
inputs: Any
"""The input video data"""
parameters: Optional[VideoClassificationParameters] = None
"""Additional inference parameters"""
@dataclass
class VideoClassificationOutputElement(BaseInferenceType):
"""Outputs of inference for the Video Classification task"""
label: str
"""The predicted class label."""
score: float
"""The corresponding probability."""

View File

@ -0,0 +1,53 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Optional
from .base import BaseInferenceType
@dataclass
class VisualQuestionAnsweringInputData(BaseInferenceType):
"""One (image, question) pair to answer"""
image: Any
"""The image."""
question: Any
"""The question to answer based on the image."""
@dataclass
class VisualQuestionAnsweringParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Visual Question Answering
"""
top_k: Optional[int] = None
"""The number of answers to return (will be chosen by order of likelihood). Note that we
return less than topk answers if there are not enough options available within the
context.
"""
@dataclass
class VisualQuestionAnsweringInput(BaseInferenceType):
"""Inputs for Visual Question Answering inference"""
inputs: VisualQuestionAnsweringInputData
"""One (image, question) pair to answer"""
parameters: Optional[VisualQuestionAnsweringParameters] = None
"""Additional inference parameters"""
@dataclass
class VisualQuestionAnsweringOutputElement(BaseInferenceType):
"""Outputs of inference for the Visual Question Answering task"""
label: Any
score: float
"""The associated score / probability"""
answer: Optional[str] = None
"""The answer to the question"""

View File

@ -0,0 +1,56 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import List, Optional
from .base import BaseInferenceType
@dataclass
class ZeroShotClassificationInputData(BaseInferenceType):
"""The input text data, with candidate labels"""
candidate_labels: List[str]
"""The set of possible class labels to classify the text into."""
text: str
"""The text to classify"""
@dataclass
class ZeroShotClassificationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Zero Shot Classification
"""
hypothesis_template: Optional[str] = None
"""The sentence used in conjunction with candidateLabels to attempt the text classification
by replacing the placeholder with the candidate labels.
"""
multi_label: Optional[bool] = None
"""Whether multiple candidate labels can be true. If false, the scores are normalized such
that the sum of the label likelihoods for each sequence is 1. If true, the labels are
considered independent and probabilities are normalized for each candidate.
"""
@dataclass
class ZeroShotClassificationInput(BaseInferenceType):
"""Inputs for Zero Shot Classification inference"""
inputs: ZeroShotClassificationInputData
"""The input text data, with candidate labels"""
parameters: Optional[ZeroShotClassificationParameters] = None
"""Additional inference parameters"""
@dataclass
class ZeroShotClassificationOutputElement(BaseInferenceType):
"""Outputs of inference for the Zero Shot Classification task"""
label: str
"""The predicted class label."""
score: float
"""The corresponding probability."""

View File

@ -0,0 +1,51 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, List, Optional
from .base import BaseInferenceType
@dataclass
class ZeroShotImageClassificationInputData(BaseInferenceType):
"""The input image data, with candidate labels"""
candidate_labels: List[str]
"""The candidate labels for this image"""
image: Any
"""The image data to classify"""
@dataclass
class ZeroShotImageClassificationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Zero Shot Image Classification
"""
hypothesis_template: Optional[str] = None
"""The sentence used in conjunction with candidateLabels to attempt the text classification
by replacing the placeholder with the candidate labels.
"""
@dataclass
class ZeroShotImageClassificationInput(BaseInferenceType):
"""Inputs for Zero Shot Image Classification inference"""
inputs: ZeroShotImageClassificationInputData
"""The input image data, with candidate labels"""
parameters: Optional[ZeroShotImageClassificationParameters] = None
"""Additional inference parameters"""
@dataclass
class ZeroShotImageClassificationOutputElement(BaseInferenceType):
"""Outputs of inference for the Zero Shot Image Classification task"""
label: str
"""The predicted class label."""
score: float
"""The corresponding probability."""

View File

@ -0,0 +1,55 @@
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Dict, List, Optional
from .base import BaseInferenceType
@dataclass
class ZeroShotObjectDetectionInputData(BaseInferenceType):
"""The input image data, with candidate labels"""
candidate_labels: List[str]
"""The candidate labels for this image"""
image: Any
"""The image data to generate bounding boxes from"""
@dataclass
class ZeroShotObjectDetectionInput(BaseInferenceType):
"""Inputs for Zero Shot Object Detection inference"""
inputs: ZeroShotObjectDetectionInputData
"""The input image data, with candidate labels"""
parameters: Optional[Dict[str, Any]] = None
"""Additional inference parameters"""
@dataclass
class ZeroShotObjectDetectionBoundingBox(BaseInferenceType):
"""The predicted bounding box. Coordinates are relative to the top left corner of the input
image.
"""
xmax: int
xmin: int
ymax: int
ymin: int
@dataclass
class ZeroShotObjectDetectionOutputElement(BaseInferenceType):
"""Outputs of inference for the Zero Shot Object Detection task"""
box: ZeroShotObjectDetectionBoundingBox
"""The predicted bounding box. Coordinates are relative to the top left corner of the input
image.
"""
label: str
"""A candidate label"""
score: float
"""The associated score / probability"""