Commit ·
77620f6
1
Parent(s): 1f29180
Fix: Link TTS and Whisper from app.state instead of reinitializing
Browse files- modules/art_reels/__init__.py +15 -1
- modules/art_reels/router.py +25 -13
modules/art_reels/__init__.py
CHANGED
|
@@ -7,11 +7,25 @@ from config import NCAkitConfig
|
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def register(app, config: NCAkitConfig):
|
| 12 |
"""Register art_reels module with the app"""
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
-
from .router import router
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Include router
|
| 17 |
app.include_router(router, prefix="/api/art", tags=["Art Reels"])
|
|
|
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
+
# Module-level app reference for accessing shared services
|
| 11 |
+
_app = None
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def get_app():
|
| 15 |
+
"""Get FastAPI app instance"""
|
| 16 |
+
return _app
|
| 17 |
+
|
| 18 |
|
| 19 |
def register(app, config: NCAkitConfig):
|
| 20 |
"""Register art_reels module with the app"""
|
| 21 |
+
global _app
|
| 22 |
+
|
| 23 |
try:
|
| 24 |
+
from .router import router, set_app_reference
|
| 25 |
+
|
| 26 |
+
# Store app reference for accessing TTS/Whisper from app.state
|
| 27 |
+
_app = app
|
| 28 |
+
set_app_reference(app)
|
| 29 |
|
| 30 |
# Include router
|
| 31 |
app.include_router(router, prefix="/api/art", tags=["Art Reels"])
|
modules/art_reels/router.py
CHANGED
|
@@ -27,6 +27,17 @@ logger = logging.getLogger(__name__)
|
|
| 27 |
|
| 28 |
router = APIRouter()
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# In-memory job storage
|
| 31 |
jobs: Dict[str, Dict] = {}
|
| 32 |
|
|
@@ -143,19 +154,20 @@ async def generate_stick_figure_video(job_id: str, script: str, voice: str):
|
|
| 143 |
from ..story_reels.services.srt_parser import SRTParser
|
| 144 |
from .services.professional_stick_figure import ProfessionalStickFigure
|
| 145 |
|
| 146 |
-
# Get TTS
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
| 159 |
|
| 160 |
update_job(job_id, "processing", 10)
|
| 161 |
|
|
|
|
| 27 |
|
| 28 |
router = APIRouter()
|
| 29 |
|
| 30 |
+
# App reference for accessing shared services (TTS, Whisper)
|
| 31 |
+
_app = None
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def set_app_reference(app):
|
| 35 |
+
"""Set FastAPI app reference for accessing shared services"""
|
| 36 |
+
global _app
|
| 37 |
+
_app = app
|
| 38 |
+
logger.info("App reference set for art_reels module")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
# In-memory job storage
|
| 42 |
jobs: Dict[str, Dict] = {}
|
| 43 |
|
|
|
|
| 154 |
from ..story_reels.services.srt_parser import SRTParser
|
| 155 |
from .services.professional_stick_figure import ProfessionalStickFigure
|
| 156 |
|
| 157 |
+
# Get TTS and Whisper clients from app.state (already initialized by story_reels)
|
| 158 |
+
if not _app or not hasattr(_app, 'state'):
|
| 159 |
+
raise Exception("App reference not available")
|
| 160 |
+
|
| 161 |
+
tts_client = getattr(_app.state, 'tts_client', None)
|
| 162 |
+
whisper_client = getattr(_app.state, 'whisper_client', None)
|
| 163 |
+
|
| 164 |
+
if not tts_client:
|
| 165 |
+
raise Exception("TTS client not available - check if story_reels module is loaded")
|
| 166 |
+
|
| 167 |
+
if not whisper_client:
|
| 168 |
+
raise Exception("Whisper client not available - check if story_reels module is loaded")
|
| 169 |
+
|
| 170 |
+
logger.info("Using TTS and Whisper clients from app.state")
|
| 171 |
|
| 172 |
update_job(job_id, "processing", 10)
|
| 173 |
|