whispering/whispering/schema.py

53 lines
1.3 KiB
Python
Raw Normal View History

2022-09-23 10:20:11 +00:00
#!/usr/bin/env python3
2022-09-24 04:12:24 +00:00
from typing import List, Optional
2022-09-23 10:20:11 +00:00
2022-09-29 11:14:56 +00:00
import torch
from pydantic import BaseModel, root_validator
2022-09-23 10:20:11 +00:00
class WhisperConfig(BaseModel):
model_name: str
device: str
language: str
2022-09-23 13:39:27 +00:00
fp16: bool = True
2022-09-23 11:03:00 +00:00
@root_validator
def validate_model_name(cls, values):
if values["model_name"].endswith(".en") and values["language"] not in {
"en",
"English",
}:
raise ValueError("English only model")
return values
2022-09-23 11:03:00 +00:00
2022-09-29 11:14:56 +00:00
class Context(BaseModel, arbitrary_types_allowed=True):
timestamp: float = 0.0
buffer_tokens: List[torch.Tensor] = []
buffer_mel: Optional[torch.Tensor] = None
2022-09-29 11:43:49 +00:00
temperatures: List[float]
allow_padding: bool = False
patience: Optional[float] = None
compression_ratio_threshold: Optional[float] = 2.4
logprob_threshold: Optional[float] = -1.0
no_captions_threshold: Optional[float] = 0.6
best_of: int = 5
beam_size: Optional[int] = None
no_speech_threshold: Optional[float] = 0.6
logprob_threshold: Optional[float] = -1.0
compression_ratio_threshold: Optional[float] = 2.4
buffer_threshold: Optional[float] = 0.5
2022-09-29 11:14:56 +00:00
2022-09-23 11:03:00 +00:00
class ParsedChunk(BaseModel):
start: float
end: float
text: str
tokens: List[int]
temperature: float
avg_logprob: float
compression_ratio: float
no_speech_prob: float