Fix: run heavy pipeline in threads to unblock event loop, mount code volumes for live updates
This commit is contained in:
parent
2eee05a52f
commit
24154665b6
@ -75,13 +75,14 @@ async def process_file(file_path: Path, task_id: str):
|
||||
|
||||
await _send_progress(task_id, 15, "Загрузка моделей ИИ...", "processing")
|
||||
|
||||
# Подготовка аудио
|
||||
audio_path = prepare_audio_input(str(file_path))
|
||||
# Подготовка аудио (в отдельном потоке, чтобы не блокировать event loop)
|
||||
audio_path = await asyncio.to_thread(prepare_audio_input, str(file_path))
|
||||
|
||||
await _send_progress(task_id, 25, "Транскрибация (распознавание речи)...", "processing")
|
||||
|
||||
# Запуск пайплайна
|
||||
result = run_pipeline(
|
||||
# Запуск пайплайна (в отдельном потоке)
|
||||
result = await asyncio.to_thread(
|
||||
run_pipeline,
|
||||
input_path=str(file_path),
|
||||
profile_name=None,
|
||||
config_path=None,
|
||||
@ -94,18 +95,18 @@ async def process_file(file_path: Path, task_id: str):
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
folder_name = f"{stem}_{timestamp}"
|
||||
output_dir = PROCESSED_DIR / folder_name
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
await asyncio.to_thread(output_dir.mkdir, parents=True, exist_ok=True)
|
||||
|
||||
# Сохраняем docx и md
|
||||
# Сохраняем docx и md (в отдельном потоке)
|
||||
docx_path = str(output_dir / f"{stem}.docx")
|
||||
md_path = str(output_dir / f"{stem}.md")
|
||||
|
||||
build_document(result["segments"], docx_path, config)
|
||||
build_document(result["segments"], md_path, config)
|
||||
await asyncio.to_thread(build_document, result["segments"], docx_path, config)
|
||||
await asyncio.to_thread(build_document, result["segments"], md_path, config)
|
||||
|
||||
# Также сохраняем исходник (всегда копируем, так как папка уникальная)
|
||||
# Также сохраняем исходник
|
||||
src_copy = output_dir / file_path.name
|
||||
shutil.copy2(str(file_path), str(src_copy))
|
||||
await asyncio.to_thread(shutil.copy2, str(file_path), str(src_copy))
|
||||
|
||||
result_data = {
|
||||
"docx": str(docx_path),
|
||||
|
||||
@ -13,6 +13,9 @@ services:
|
||||
- uploads:/app/uploads
|
||||
- processed:/app/processed
|
||||
- tmp:/app/tmp
|
||||
- ./backend:/app/backend:ro
|
||||
- ./src:/app/src:ro
|
||||
- ./scripts:/app/scripts:ro
|
||||
restart: unless-stopped
|
||||
entrypoint: ["uvicorn"]
|
||||
command: ["backend.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user