|
23 | 23 | from labelbox.orm.db_object import DbObject
|
24 | 24 | from labelbox.orm.model import Entity, Field
|
25 | 25 | from labelbox.pagination import PaginatedCollection
|
| 26 | +from labelbox.project_validation import _CoreProjectInput |
26 | 27 | from labelbox.schema import role
|
27 | 28 | from labelbox.schema.catalog import Catalog
|
28 | 29 | from labelbox.schema.data_row import DataRow
|
@@ -632,7 +633,8 @@ def create_project(self, **kwargs) -> Project:
|
632 | 633 | kwargs.pop("append_to_existing_dataset", None)
|
633 | 634 | kwargs.pop("data_row_count", None)
|
634 | 635 | kwargs.pop("editor_task_type", None)
|
635 |
| - return self._create_project(**kwargs) |
| 636 | + input = _CoreProjectInput(**kwargs) |
| 637 | + return self._create_project(input) |
636 | 638 |
|
637 | 639 | @overload
|
638 | 640 | def create_model_evaluation_project(
|
@@ -820,103 +822,10 @@ def create_response_creation_project(self, **kwargs) -> Project:
|
820 | 822 |
|
821 | 823 | return self._create_project(**kwargs)
|
822 | 824 |
|
823 |
| - def _create_project(self, **kwargs) -> Project: |
824 |
| - auto_audit_percentage = kwargs.get("auto_audit_percentage") |
825 |
| - auto_audit_number_of_labels = kwargs.get("auto_audit_number_of_labels") |
826 |
| - if ( |
827 |
| - auto_audit_percentage is not None |
828 |
| - or auto_audit_number_of_labels is not None |
829 |
| - ): |
830 |
| - raise ValueError( |
831 |
| - "quality_modes must be set instead of auto_audit_percentage or auto_audit_number_of_labels." |
832 |
| - ) |
833 |
| - |
834 |
| - name = kwargs.get("name") |
835 |
| - if name is None or not name.strip(): |
836 |
| - raise ValueError("project name must be a valid string.") |
837 |
| - |
838 |
| - queue_mode = kwargs.get("queue_mode") |
839 |
| - if queue_mode is QueueMode.Dataset: |
840 |
| - raise ValueError( |
841 |
| - "Dataset queue mode is deprecated. Please prefer Batch queue mode." |
842 |
| - ) |
843 |
| - elif queue_mode is QueueMode.Batch: |
844 |
| - logger.warning( |
845 |
| - "Passing a queue mode of batch is redundant and will soon no longer be supported." |
846 |
| - ) |
847 |
| - |
848 |
| - media_type = kwargs.get("media_type") |
849 |
| - if media_type and MediaType.is_supported(media_type): |
850 |
| - media_type_value = media_type.value |
851 |
| - elif media_type: |
852 |
| - raise TypeError( |
853 |
| - f"{media_type} is not a valid media type. Use" |
854 |
| - f" any of {MediaType.get_supported_members()}" |
855 |
| - " from MediaType. Example: MediaType.Image." |
856 |
| - ) |
857 |
| - else: |
858 |
| - logger.warning( |
859 |
| - "Creating a project without specifying media_type" |
860 |
| - " through this method will soon no longer be supported." |
861 |
| - ) |
862 |
| - media_type_value = None |
863 |
| - |
864 |
| - quality_modes = kwargs.get("quality_modes") |
865 |
| - quality_mode = kwargs.get("quality_mode") |
866 |
| - if quality_mode: |
867 |
| - logger.warning( |
868 |
| - "Passing quality_mode is deprecated and will soon no longer be supported. Use quality_modes instead." |
869 |
| - ) |
870 |
| - |
871 |
| - if quality_modes and quality_mode: |
872 |
| - raise ValueError( |
873 |
| - "Cannot use both quality_modes and quality_mode at the same time. Use one or the other." |
874 |
| - ) |
875 |
| - |
876 |
| - if not quality_modes and not quality_mode: |
877 |
| - logger.info("Defaulting quality modes to Benchmark and Consensus.") |
878 |
| - |
879 |
| - data = kwargs |
880 |
| - data.pop("quality_modes", None) |
881 |
| - data.pop("quality_mode", None) |
882 |
| - |
883 |
| - # check if quality_modes is a set, if not, convert to set |
884 |
| - quality_modes_set = quality_modes |
885 |
| - if quality_modes and not isinstance(quality_modes, set): |
886 |
| - quality_modes_set = set(quality_modes) |
887 |
| - if quality_mode: |
888 |
| - quality_modes_set = {quality_mode} |
889 |
| - |
890 |
| - if ( |
891 |
| - quality_modes_set is None |
892 |
| - or len(quality_modes_set) == 0 |
893 |
| - or quality_modes_set |
894 |
| - == {QualityMode.Benchmark, QualityMode.Consensus} |
895 |
| - ): |
896 |
| - data["auto_audit_number_of_labels"] = ( |
897 |
| - CONSENSUS_AUTO_AUDIT_NUMBER_OF_LABELS |
898 |
| - ) |
899 |
| - data["auto_audit_percentage"] = CONSENSUS_AUTO_AUDIT_PERCENTAGE |
900 |
| - data["is_benchmark_enabled"] = True |
901 |
| - data["is_consensus_enabled"] = True |
902 |
| - elif quality_modes_set == {QualityMode.Benchmark}: |
903 |
| - data["auto_audit_number_of_labels"] = ( |
904 |
| - BENCHMARK_AUTO_AUDIT_NUMBER_OF_LABELS |
905 |
| - ) |
906 |
| - data["auto_audit_percentage"] = BENCHMARK_AUTO_AUDIT_PERCENTAGE |
907 |
| - data["is_benchmark_enabled"] = True |
908 |
| - elif quality_modes_set == {QualityMode.Consensus}: |
909 |
| - data["auto_audit_number_of_labels"] = ( |
910 |
| - CONSENSUS_AUTO_AUDIT_NUMBER_OF_LABELS |
911 |
| - ) |
912 |
| - data["auto_audit_percentage"] = CONSENSUS_AUTO_AUDIT_PERCENTAGE |
913 |
| - data["is_consensus_enabled"] = True |
914 |
| - else: |
915 |
| - raise ValueError( |
916 |
| - f"{quality_modes_set} is not a valid quality modes set. Allowed values are [Benchmark, Consensus]" |
917 |
| - ) |
| 825 | + def _create_project(self, input: _CoreProjectInput) -> Project: |
| 826 | + media_type_value = input.media_type.value |
918 | 827 |
|
919 |
| - params = {**data} |
| 828 | + params = input.model_dump(exclude_none=True) |
920 | 829 | if media_type_value:
|
921 | 830 | params["media_type"] = media_type_value
|
922 | 831 |
|
|
0 commit comments