Samfredoly commited on
Commit
8b1aea6
·
verified ·
1 Parent(s): f58b066

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -5,6 +5,7 @@ import asyncio
5
  import aiohttp
6
  import zipfile
7
  import shutil
 
8
  from typing import Dict, List, Set, Optional, Tuple, Any
9
  from urllib.parse import quote
10
  from datetime import datetime
@@ -494,16 +495,21 @@ app = FastAPI(
494
 
495
  @app.on_event("startup")
496
  async def startup_event():
497
- print(f"Flow Server {FLOW_ID} started on port {FLOW_PORT}.")
 
 
 
 
 
 
498
 
499
  @app.post("/process")
500
  async def process_audio_files(background_tasks: BackgroundTasks):
501
  """
502
- Main processing endpoint that orchestrates transcription of audio files.
503
- Fetches audio from HF dataset, sends to Whisper servers, and uploads results.
504
- Uses reference file mapping for output filename renaming.
505
  """
506
- print(f"[{FLOW_ID}] /process endpoint called, starting background task...")
507
  background_tasks.add_task(process_audio_files_background)
508
  return {
509
  "status": "processing_started",
@@ -511,8 +517,6 @@ async def process_audio_files(background_tasks: BackgroundTasks):
511
  "message": "Background processing task started. Check /status for progress."
512
  }
513
 
514
- # No wrapper needed - add_task can handle coroutine functions directly in newer FastAPI
515
-
516
  async def process_audio_files_background():
517
  """Background task that processes audio files with reference mapping."""
518
  progress_data = load_progress()
 
5
  import aiohttp
6
  import zipfile
7
  import shutil
8
+ import threading
9
  from typing import Dict, List, Set, Optional, Tuple, Any
10
  from urllib.parse import quote
11
  from datetime import datetime
 
495
 
496
  @app.on_event("startup")
497
  async def startup_event():
498
+ print(f"[{FLOW_ID}] Flow Server started on port {FLOW_PORT}.")
499
+ print(f"[{FLOW_ID}] 🚀 Auto-starting background processing...")
500
+
501
+ # Create a background task to run the processing loop
502
+ thread = threading.Thread(target=lambda: asyncio.run(process_audio_files_background()), daemon=True)
503
+ thread.start()
504
+ print(f"[{FLOW_ID}] ✅ Background processing thread started")
505
 
506
  @app.post("/process")
507
  async def process_audio_files(background_tasks: BackgroundTasks):
508
  """
509
+ Manually trigger processing endpoint (in addition to auto-start on startup).
510
+ Orchestrates transcription of audio files with reference file mapping.
 
511
  """
512
+ print(f"[{FLOW_ID}] /process endpoint called, starting additional background task...")
513
  background_tasks.add_task(process_audio_files_background)
514
  return {
515
  "status": "processing_started",
 
517
  "message": "Background processing task started. Check /status for progress."
518
  }
519
 
 
 
520
  async def process_audio_files_background():
521
  """Background task that processes audio files with reference mapping."""
522
  progress_data = load_progress()