Spaces:
Sleeping
Sleeping
| from pydantic import BaseModel, create_model | |
| from typing import Literal, List | |
| def generate_classification_model(labels: List[str]) -> BaseModel: | |
| """ | |
| Dynamically generates a Pydantic model for classification based on user-provided labels. | |
| Args: | |
| labels (List[str]): List of valid label strings. | |
| Returns: | |
| BaseModel: A dynamically generated Pydantic model. | |
| """ | |
| return create_model( | |
| "DynamicClassificationOutput", | |
| label=(Literal[tuple(labels)], ...), # Enforce that 'label' matches one of the valid labels | |
| ) | |