| import asyncio |
| from dataclasses import dataclass |
|
|
|
|
| |
| |
| |
|
|
| @dataclass |
| class Context: |
| input_file: any = None |
| url_input: str = None |
| params: dict = None |
|
|
|
|
| def normalize_context(ctx): |
| if isinstance(ctx, dict): |
| return Context( |
| input_file=ctx.get("input_file"), |
| url_input=ctx.get("url_input"), |
| params=ctx.get("params", {}) or {} |
| ) |
| return ctx |
|
|
|
|
| |
| |
| |
|
|
| async def run(context): |
| """ |
| Autonomous pipeline: |
| 1. Transcribe |
| 2. Extract highlights |
| 3. Compute viral score |
| 4. Generate strategy |
| """ |
|
|
| context = normalize_context(context) |
|
|
| try: |
| |
| |
| |
| from publisher.tasks.transcribe import run as transcribe_task |
|
|
| transcript = await transcribe_task(context) |
|
|
| if transcript.get("status") != "success": |
| return { |
| "status": "error", |
| "stage": "transcribe", |
| "detail": transcript |
| } |
|
|
| |
| |
| |
| from publisher.tasks.highlights import run as highlights_task |
|
|
| highlights = await highlights_task(context) |
|
|
| |
| |
| |
| from publisher.tasks.viral_score import run as viral_task |
|
|
| viral = await viral_task(context) |
|
|
| |
| |
| |
| from publisher.tasks.strategy import run as strategy_task |
|
|
| strategy = await strategy_task(context) |
|
|
| |
| |
| |
|
|
| segments = transcript.get("segments", []) |
| full_text = " ".join([s["text"] for s in segments]) |
|
|
| return { |
| "status": "success", |
| "pipeline": "autonomous-v11", |
| "summary": { |
| "segments": len(segments), |
| "highlights": highlights.get("count", 0), |
| "viral_score": viral.get("viral_score", 0), |
| }, |
| "transcript": { |
| "text": full_text, |
| "segments": segments |
| }, |
| "highlights": highlights.get("highlights", []), |
| "viral": viral, |
| "strategy": strategy |
| } |
|
|
| except Exception as e: |
| return { |
| "status": "error", |
| "message": str(e), |
| "stage": "autonomous_pipeline_failed" |
| } |