Spaces:
Running
Running
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey | |
from sqlalchemy.orm import relationship, declarative_base | |
from pydantic import BaseModel, ConfigDict | |
from typing import List | |
from datetime import datetime | |
Base = declarative_base() | |
class Annotator(Base): | |
__tablename__ = 'annotators' | |
id = Column(Integer, primary_key=True) | |
name = Column(String, nullable=False, unique=True) | |
password = Column(String, nullable=False) | |
last_login = Column(DateTime) | |
is_active = Column(Boolean, default=True) | |
annotations = relationship('Annotation', backref='annotator') | |
validators = relationship('Validator', backref='annotator') | |
annotation_intervals = relationship('AnnotationInterval', backref='annotator') | |
class Validator(Base): | |
__tablename__ = 'validators' | |
id = Column(Integer, primary_key=True) | |
annotator_id = Column(Integer, ForeignKey('annotators.id')) | |
validator_id = Column(Integer, ForeignKey('annotators.id')) | |
class AnnotationInterval(Base): | |
__tablename__ = 'annotation_intervals' | |
id = Column(Integer, primary_key=True) | |
annotator_id = Column(Integer, ForeignKey('annotators.id')) | |
start_index = Column(Integer, nullable=True) | |
end_index = Column(Integer, nullable=True) | |
class AudioTrim(Base): | |
__tablename__ = 'audio_trims' | |
id = Column(Integer, primary_key=True) | |
start = Column(Float, nullable=False) | |
end = Column(Float, nullable=False) | |
annotation_id = Column(Integer, ForeignKey('annotations.id')) | |
class Annotation(Base): | |
__tablename__ = 'annotations' | |
id = Column(Integer, primary_key=True) | |
annotated_subtitle = Column(String, nullable=False) | |
validated = Column(Boolean, nullable=False) | |
create_at = Column(DateTime, nullable=False) | |
update_at = Column(DateTime, nullable=False) | |
audio_trims = relationship('AudioTrim', cascade='all, delete', backref='annotation') | |
json_data_id = Column(Integer, ForeignKey('json_data.id')) | |
annotator_id = Column(Integer, ForeignKey('annotators.id')) | |
class AudioTrimModel(BaseModel): | |
start: float | |
end: float | |
model_config = ConfigDict(from_attributes=True) | |
class AnnotationModel(BaseModel): | |
annotator: str | |
annotated_subtitle: str | |
is_first_phase_accepted: bool | |
create_at: datetime | |
update_at: datetime | |
audio_trims: List[AudioTrimModel] | |
model_config = ConfigDict(from_attributes=True) | |
class JsonDataModel(BaseModel): | |
id: int | |
voice_name: str | |
original_subtitle: str | |
ignore_it: bool | |
is_approved_in_second_phase: bool | |
annotations: List[AnnotationModel] | |
model_config = ConfigDict(from_attributes=True) |