Mbonea commited on
Commit
3a6cb04
·
1 Parent(s): a596b5c

finally we have text!

Browse files
Files changed (1) hide show
  1. App/Generate/database/Model.py +29 -3
App/Generate/database/Model.py CHANGED
@@ -7,12 +7,36 @@ from .DescriptAPI import Speak
7
  from .Vercel import AsyncImageGenerator
8
  import aiohttp
9
  from typing import List
 
 
10
 
11
  database_url = "sqlite+aiosqlite:///ok.db"
12
  database = databases.Database(database_url)
13
  models = orm.ModelRegistry(database=database)
14
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  class Project(orm.Model):
17
  tablename = "projects"
18
  start = 0
@@ -121,9 +145,11 @@ class Project(orm.Model):
121
  "width": 1080,
122
  }
123
  try:
124
- data = await self.generate_transcript()
125
- print(data)
126
- except:
 
 
127
  pass
128
 
129
  await self.update(**self.__dict__)
 
7
  from .Vercel import AsyncImageGenerator
8
  import aiohttp
9
  from typing import List
10
+ from pydantic import BaseModel
11
+ import json
12
 
13
  database_url = "sqlite+aiosqlite:///ok.db"
14
  database = databases.Database(database_url)
15
  models = orm.ModelRegistry(database=database)
16
 
17
 
18
+ class WordAlignment(BaseModel):
19
+ text: str
20
+ alignedWord: str
21
+ start: float
22
+ end: float
23
+ hasFailedAlignment: bool
24
+
25
+ @classmethod
26
+ def from_old_format(cls, data: dict):
27
+ return cls(
28
+ text=data["word"],
29
+ alignedWord=data["alignedWord"],
30
+ start=data["startTime"],
31
+ end=data["endTime"],
32
+ hasFailedAlignment=data["hasFailedAlignment"],
33
+ )
34
+
35
+
36
+ def transform_alignment_data(data: List[dict]) -> List[dict]:
37
+ return [WordAlignment.from_old_format(item).model_dump() for item in data]
38
+
39
+
40
  class Project(orm.Model):
41
  tablename = "projects"
42
  start = 0
 
145
  "width": 1080,
146
  }
147
  try:
148
+ text_stream = await self.generate_transcript()
149
+ self.assets.append({"type": "text", "sequence": text_stream})
150
+
151
+ except Exception as e:
152
+ print(f"Text sequence failed, {e}")
153
  pass
154
 
155
  await self.update(**self.__dict__)