Spaces:
Sleeping
Sleeping
| from app.services.enrichment.normalize import normalize_text | |
| from app.services.enrichment.title_keywords import extract_title_and_keywords | |
| from app.services.enrichment.summary import generate_summary | |
| from app.services.enrichment.mindmap import generate_mindmap | |
| # dùng cho regenerate / batch | |
| async def run_pipeline(note: dict, tasks: list[str]): | |
| raw_text = note.get("raw_text") or "" | |
| if not raw_text.strip(): | |
| # Nothing to process | |
| return note | |
| text = raw_text | |
| # 1️⃣ Normalize | |
| if "normalize" in tasks: | |
| try: | |
| text = await normalize_text(text) | |
| note["normalized_text"] = text | |
| except Exception: | |
| # Fail-safe: keep raw_text | |
| note["normalized_text"] = text | |
| # 2️⃣ Title + Keywords (same AI call) | |
| if "keywords" in tasks: | |
| try: | |
| title, keywords = await extract_title_and_keywords(text) | |
| if title: | |
| note["title"] = title | |
| if keywords: | |
| note["keywords"] = keywords | |
| except Exception: | |
| # Fail-safe: skip title & keywords | |
| pass | |
| # 3️⃣ Summary | |
| if "summary" in tasks: | |
| try: | |
| note["summary"] = await generate_summary(text) | |
| except Exception: | |
| pass | |
| # 4️⃣ Mindmap | |
| if "mindmap" in tasks: | |
| try: | |
| note["mindmap"] = await generate_mindmap(text) | |
| except Exception: | |
| pass | |
| return note |