2025-05-24 12:15:48 +02:00

44 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""examples/demo_run_tsne_export.py
Launch TsneExportWorker via FlowArtifact wrapper.
"""
from __future__ import annotations
import asyncio
import logging
from pathlib import Path
import os
from librarian_vspace.vecview.tsne_export_worker import TsneExportWorker, TsneExportInput
from librarian_core.workers.base import FlowArtifact
COURSE_ID = 18240 # choose a course with embeddings
logger = logging.getLogger(__name__)
def _load_env(path: Path) -> None:
if not path.is_file():
return
for line in path.read_text().splitlines():
if line.strip() and not line.startswith("#") and "=" in line:
k, v = [p.strip() for p in line.split("=", 1)]
os.environ.setdefault(k, v)
async def _main() -> None:
payload = TsneExportInput(course_id=COURSE_ID)
worker = TsneExportWorker()
art = FlowArtifact.new(run_id="", dir=Path.cwd(), data=payload)
result_artifact = await worker.flow()(art) # FlowArtifact
output = result_artifact.data # TsneExportOutput
logger.info("✅ Worker finished JSON file: %s", output.json_path)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")
APP_DIR = Path(__file__).resolve().parent
_load_env(APP_DIR / ".env")
asyncio.run(_main())