Skip to content

Commit

Permalink
add endpoint to generate webvtt export
Browse files Browse the repository at this point in the history
  • Loading branch information
rroohhh committed Dec 28, 2023
1 parent 40f304e commit 3944cb7
Show file tree
Hide file tree
Showing 16 changed files with 738 additions and 8 deletions.
175 changes: 175 additions & 0 deletions backend/openapi-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,69 @@ components:
- has_full_access
title: DocumentWithAccessInfo
type: object
ExportError:
properties:
error:
title: Error
type: string
required:
- error
title: ExportError
type: object
ExportFormat:
description: An enumeration.
enum:
- VTT
- SRT
title: ExportFormat
type: string
ExportResult:
properties:
result:
title: Result
type: string
required:
- result
title: ExportResult
type: object
ExportTask:
properties:
document_id:
format: uuid
title: Document Id
type: string
task_parameters:
$ref: '#/components/schemas/ExportTaskParameters'
task_type:
default: EXPORT
enum:
- EXPORT
title: Task Type
type: string
required:
- task_parameters
- document_id
title: ExportTask
type: object
ExportTaskParameters:
properties:
format:
$ref: '#/components/schemas/ExportFormat'
include_speaker_names:
title: Include Speaker Names
type: boolean
include_word_timing:
title: Include Word Timing
type: boolean
max_line_length:
title: Max Line Length
type: integer
required:
- format
- include_speaker_names
- include_word_timing
title: ExportTaskParameters
type: object
HTTPValidationError:
properties:
detail:
Expand Down Expand Up @@ -529,6 +592,7 @@ components:
- TRANSCRIBE
- ALIGN
- REENCODE
- EXPORT
title: TaskType
type: string
TranscribeTask:
Expand Down Expand Up @@ -887,6 +951,57 @@ paths:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: Update Document
/api/v1/documents/{document_id}/add_export_result/:
post:
operationId: add_export_result_api_v1_documents__document_id__add_export_result__post
parameters:
- in: path
name: document_id
required: true
schema:
format: uuid
title: Document Id
type: string
- in: query
name: task_id
required: true
schema:
title: Task Id
type: string
- in: header
name: authorization
required: false
schema:
title: Authorization
type: string
- in: header
name: Share-Token
required: false
schema:
title: Share-Token
type: string
requestBody:
content:
application/json:
schema:
anyOf:
- $ref: '#/components/schemas/ExportResult'
- $ref: '#/components/schemas/ExportError'
title: Result
required: true
responses:
'200':
content:
application/json:
schema: {}
description: Successful Response
'422':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: Add Export Result
/api/v1/documents/{document_id}/add_media_file/:
post:
operationId: add_media_file_api_v1_documents__document_id__add_media_file__post
Expand Down Expand Up @@ -924,6 +1039,65 @@ paths:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: Add Media File
/api/v1/documents/{document_id}/export/:
get:
operationId: export_api_v1_documents__document_id__export__get
parameters:
- in: path
name: document_id
required: true
schema:
format: uuid
title: Document Id
type: string
- in: query
name: format
required: true
schema:
$ref: '#/components/schemas/ExportFormat'
- in: query
name: include_speaker_names
required: true
schema:
title: Include Speaker Names
type: boolean
- in: query
name: include_word_timing
required: true
schema:
title: Include Word Timing
type: boolean
- in: query
name: max_line_length
required: false
schema:
title: Max Line Length
type: integer
- in: header
name: authorization
required: false
schema:
title: Authorization
type: string
- in: header
name: Share-Token
required: false
schema:
title: Share-Token
type: string
responses:
'200':
content:
application/json:
schema: {}
description: Successful Response
'422':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: Export
/api/v1/documents/{document_id}/set_duration/:
post:
operationId: set_duration_api_v1_documents__document_id__set_duration__post
Expand Down Expand Up @@ -1211,6 +1385,7 @@ paths:
- $ref: '#/components/schemas/SpeakerIdentificationTask'
- $ref: '#/components/schemas/TranscribeTask'
- $ref: '#/components/schemas/AlignTask'
- $ref: '#/components/schemas/ExportTask'
- $ref: '#/components/schemas/UnknownTask'
title: Task
required: true
Expand Down
25 changes: 24 additions & 1 deletion backend/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ authors = [
]

dependencies = [
"redis>=5.0.1",
"fastapi>=0.92.0",
"uvicorn[standard]>=0.20.0",
"sqlmodel @ git+https://github.com/transcribee/sqlmodel.git@transcribee_main",
Expand Down
3 changes: 3 additions & 0 deletions backend/transcribee_backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class Settings(BaseSettings):
metrics_username = "transcribee"
metrics_password = "transcribee"

redis_host = "localhost"
redis_port = 6379


class ModelConfig(BaseModel):
id: str
Expand Down
10 changes: 10 additions & 0 deletions backend/transcribee_backend/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
from fastapi import Request
from prometheus_client import Histogram
from prometheus_fastapi_instrumentator import routing
from redis.asyncio import Redis
from sqlalchemy import event
from sqlmodel import Session, create_engine
from starlette.websockets import WebSocket

from transcribee_backend.config import settings
from transcribee_backend.util.redis_task_channel import RedisTaskChannel

DEFAULT_SOCKET_PATH = Path(__file__).parent.parent.parent / "db" / "sockets"

DATABASE_URL = os.environ.get(
Expand All @@ -18,6 +22,8 @@
)

engine = create_engine(DATABASE_URL)
redis = Redis(host=settings.redis_host, port=settings.redis_port)
redis_task_channel = RedisTaskChannel(redis)

query_histogram = Histogram(
"sql_queries",
Expand All @@ -27,6 +33,10 @@
)


def get_redis_task_channel():
return redis_task_channel


def get_session(request: Request):
handler = routing.get_route_name(request)
with Session(engine) as session, query_counter(session, path=handler):
Expand Down
11 changes: 9 additions & 2 deletions backend/transcribee_backend/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlmodel import JSON, Column, Field, ForeignKey, Relationship, SQLModel, col
from sqlmodel.sql.sqltypes import GUID
from transcribee_proto.api import Document as ApiDocument
from transcribee_proto.api import TaskType
from transcribee_proto.api import ExportTaskParameters, TaskType
from typing_extensions import Self

from transcribee_backend.config import settings
Expand Down Expand Up @@ -291,9 +291,16 @@ class AlignTask(TaskBase):
task_parameters: Dict[str, Any]


class ExportTask(TaskBase):
task_type: Literal[TaskType.EXPORT] = TaskType.EXPORT
task_parameters: ExportTaskParameters


class UnknownTask(TaskBase):
task_type: str
task_parameters: Dict[str, Any]


CreateTask = SpeakerIdentificationTask | TranscribeTask | AlignTask | UnknownTask
CreateTask = (
SpeakerIdentificationTask | TranscribeTask | AlignTask | ExportTask | UnknownTask
)
Loading

0 comments on commit 3944cb7

Please sign in to comment.