import os from typing import Dict, Any import uvicorn from fastapi import FastAPI, Body from fastapi.responses import HTMLResponse import requests from bs4 import BeautifulSoup from .shl.indexer import load_catalog from .shl.recommender import Recommender app = FastAPI() catalog_items = 0 rec = None def jd_from_url(u: str) -> str: hdrs = {"User-Agent": "Mozilla/5.0"} try: r = requests.get(u, headers=hdrs, timeout=30) soup = BeautifulSoup(r.text, "html.parser") for s in soup(["script", "style", "noscript"]): s.decompose() txt = " ".join(soup.get_text(separator=" ").split()) return txt[:5000] except Exception: return "" @app.on_event("startup") def on_startup(): global catalog_items catalog_items = len(load_catalog()) auto_build = os.getenv("AUTO_BUILD", "false").lower() == "true" if auto_build and catalog_items == 0: try: from .shl.scraper import run as scrape_run from .shl.indexer import index as index_run scrape_run() index_run() catalog_items = len(load_catalog()) except Exception: pass @app.get("/health") def health(): return {"status": "ok", "catalog_items": catalog_items, "embedding_model": "all-MiniLM-L6-v2"} @app.get("/", response_class=HTMLResponse) def index(): html = """
| Name | URL | Type |
|---|