ismdrobiul489 commited on
Commit
77620f6
·
1 Parent(s): 1f29180

Fix: Link TTS and Whisper from app.state instead of reinitializing

Browse files
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 client from app
147
- import sys
148
- app_module = sys.modules.get('app')
149
- tts_client = getattr(app_module, 'tts_client', None) if app_module else None
150
- whisper_client = getattr(app_module, 'whisper_client', None) if app_module else None
151
-
152
- if not tts_client or not whisper_client:
153
- # Fallback: try to get from story_reels module
154
- try:
155
- from modules.story_reels import get_clients
156
- tts_client, whisper_client = get_clients()
157
- except:
158
- raise Exception("TTS and Whisper clients not available")
 
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