Add MCP-style API server (OpenAPI) alongside WebUI
Mirror and run GitLab CI / build (push) Waiting to run
Ruff / ruff (push) Waiting to run

- New mcp_server.py: FastAPI app for LLMs to upload audio and get transcript JSON.
- Added process_mcp_transcribe_task Celery task.
- Updated __main__.py: WebUI always runs; MCP server runs in parallel when MCP_SERVER_ENABLED=true.
This commit is contained in:
admin
2026-06-19 17:04:44 +00:00
parent 111d1ea18b
commit 54414def26
3 changed files with 301 additions and 1 deletions
+65
View File
@@ -504,3 +504,68 @@ def process_transcription_task(
if audio_path:
_remove_file(audio_path)
logger.info("Cleanup completed for job %s.", task_id)
@celery_app.task(
name="scraibe.tasks.process_mcp_transcribe_task",
bind=True,
max_retries=1,
task_time_limit=14400,
task_soft_time_limit=13500,
)
def process_mcp_transcribe_task(
self,
audio_path: str,
job_id: str,
language: str,
num_speakers: int,
):
"""
Async task used by MCP-style API:
- Transcribe audio
- Store transcript + segments in shared MCP job store
- Clean up temporary file
"""
from .mcp_server import _mcp_jobs
log_level = os.getenv("LOG_LEVEL", "INFO")
setup_logging(level=log_level)
# Initialize status
_mcp_jobs.setdefault(
job_id,
{
"status": "processing",
"message": "Transcription started (async).",
"file_path": audio_path,
},
)
try:
scraibe = Scraibe(verbose=True)
result = scraibe.transcribe(
audio_file=audio_path,
language=language or None,
num_speakers=int(num_speakers) if num_speakers else None,
verbose=True,
for_export=True,
)
transcript_text = result.get("transcript", "")
segments = result.get("segments", [])
_mcp_jobs[job_id]["status"] = "completed"
_mcp_jobs[job_id]["transcript"] = transcript_text
_mcp_jobs[job_id]["segments"] = segments
_mcp_jobs[job_id]["message"] = "Transcription completed."
logger.info("MCP job %s completed.", job_id)
except Exception as e:
logger.error("MCP job %s failed: %s", job_id, e, exc_info=True)
_mcp_jobs[job_id]["status"] = "error"
_mcp_jobs[job_id]["message"] = f"Transcription error: {e}"
finally:
_remove_file(audio_path)
logger.info("MCP job %s cleanup completed.", job_id)