You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
1.3 KiB

from typing import Type
from projects.models import (
DOCUMENT_CLASSIFICATION,
SEQUENCE_LABELING,
SEQ2SEQ,
SPEECH2TEXT,
IMAGE_CLASSIFICATION,
INTENT_DETECTION_AND_SLOT_FILLING,
)
from . import catalog, repositories, writers
def create_repository(project):
mapping = {
DOCUMENT_CLASSIFICATION: repositories.TextClassificationRepository,
SEQUENCE_LABELING: repositories.SequenceLabelingRepository,
SEQ2SEQ: repositories.Seq2seqRepository,
IMAGE_CLASSIFICATION: repositories.FileRepository,
SPEECH2TEXT: repositories.Speech2TextRepository,
INTENT_DETECTION_AND_SLOT_FILLING: repositories.IntentDetectionSlotFillingRepository,
}
if project.project_type not in mapping:
ValueError(f"Invalid project type: {project.project_type}")
repository = mapping[project.project_type](project)
return repository
def create_writer(file_format: str) -> Type[writers.BaseWriter]:
mapping = {
catalog.CSV.name: writers.CsvWriter,
catalog.JSON.name: writers.JSONWriter,
catalog.JSONL.name: writers.JSONLWriter,
catalog.FastText.name: writers.FastTextWriter,
catalog.IntentAndSlot.name: writers.IntentAndSlotWriter,
}
if file_format not in mapping:
ValueError(f"Invalid format: {file_format}")
return mapping[file_format]