separate workers
Browse files- App/Generate/database/Model.py +4 -3
- App/app.py +14 -3
App/Generate/database/Model.py
CHANGED
|
@@ -10,7 +10,7 @@ from typing import List
|
|
| 10 |
from pydantic import BaseModel
|
| 11 |
import json
|
| 12 |
|
| 13 |
-
database_url = "sqlite+aiosqlite:///
|
| 14 |
database = databases.Database(database_url)
|
| 15 |
models = orm.ModelRegistry(database=database)
|
| 16 |
|
|
@@ -208,8 +208,9 @@ class Scene(orm.Model):
|
|
| 208 |
print("Failed to generate narration after 3 attempts.")
|
| 209 |
|
| 210 |
def calculate_durations(self):
|
| 211 |
-
|
| 212 |
-
|
|
|
|
| 213 |
self.image_duration = self.narration_duration / len(self.image_prompts)
|
| 214 |
|
| 215 |
async def generate_images(self):
|
|
|
|
| 10 |
from pydantic import BaseModel
|
| 11 |
import json
|
| 12 |
|
| 13 |
+
database_url = f"sqlite+aiosqlite:///{str(uuid.uuid4())}.db"
|
| 14 |
database = databases.Database(database_url)
|
| 15 |
models = orm.ModelRegistry(database=database)
|
| 16 |
|
|
|
|
| 208 |
print("Failed to generate narration after 3 attempts.")
|
| 209 |
|
| 210 |
def calculate_durations(self):
|
| 211 |
+
file_format = self.narration_path.split(".")[-1]
|
| 212 |
+
audio_file = AudioSegment.from_file(self.narration_path, format=file_format)
|
| 213 |
+
self.narration_duration = int(len(audio_file) / 1000)
|
| 214 |
self.image_duration = self.narration_duration / len(self.image_prompts)
|
| 215 |
|
| 216 |
async def generate_images(self):
|
App/app.py
CHANGED
|
@@ -2,7 +2,12 @@ from fastapi import FastAPI, BackgroundTasks
|
|
| 2 |
from .Editor.editorRoutes import videditor_router
|
| 3 |
from App import bot
|
| 4 |
from App.utilis import WorkerClient, SERVER_STATE
|
| 5 |
-
from .Generate.generatorRoutes import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
manager = WorkerClient()
|
|
@@ -10,11 +15,17 @@ manager = WorkerClient()
|
|
| 10 |
|
| 11 |
@app.on_event("startup")
|
| 12 |
async def startup_event():
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
except:
|
| 16 |
-
|
| 17 |
finally:
|
|
|
|
| 18 |
if not database.is_connected:
|
| 19 |
await database.connect()
|
| 20 |
await database.execute("pragma journal_mode=wal;")
|
|
|
|
| 2 |
from .Editor.editorRoutes import videditor_router
|
| 3 |
from App import bot
|
| 4 |
from App.utilis import WorkerClient, SERVER_STATE
|
| 5 |
+
from .Generate.generatorRoutes import (
|
| 6 |
+
generator_router,
|
| 7 |
+
database,
|
| 8 |
+
models,
|
| 9 |
+
)
|
| 10 |
+
import uuid
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
manager = WorkerClient()
|
|
|
|
| 15 |
|
| 16 |
@app.on_event("startup")
|
| 17 |
async def startup_event():
|
| 18 |
+
app.state.db = database
|
| 19 |
+
app.state.models = models
|
| 20 |
+
|
| 21 |
try:
|
| 22 |
+
# print(type(database.url), database_url)
|
| 23 |
+
# await models.create_all()
|
| 24 |
+
await models._create_all(str(database.url))
|
| 25 |
except:
|
| 26 |
+
print("failed to create")
|
| 27 |
finally:
|
| 28 |
+
print(database.is_connected)
|
| 29 |
if not database.is_connected:
|
| 30 |
await database.connect()
|
| 31 |
await database.execute("pragma journal_mode=wal;")
|