Spaces:
Runtime error
Runtime error
from typing import List, Optional, Union | |
from pydantic import Field, validator | |
from inference.core.entities.requests.inference import ( | |
BaseRequest, | |
InferenceRequestImage, | |
) | |
class DoctrOCRInferenceRequest(BaseRequest): | |
""" | |
DocTR inference request. | |
Attributes: | |
api_key (Optional[str]): Roboflow API Key. | |
""" | |
image: Union[List[InferenceRequestImage], InferenceRequestImage] | |
doctr_version_id: Optional[str] = "default" | |
model_id: Optional[str] = Field(None) | |
# TODO[pydantic]: We couldn't refactor the `validator`, please replace it by `field_validator` manually. | |
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-validators for more information. | |
def validate_model_id(cls, value, values): | |
if value is not None: | |
return value | |
if values.get("doctr_version_id") is None: | |
return None | |
return f"doctr/{values['doctr_version_id']}" | |