Spaces:
Running on Zero

File size: 1,603 Bytes
63e6dfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from functools import lru_cache
from .kb import load_kb, build_atoms, Retriever
from .jobs import analyze_offer
from .match import match
from .generate import generate_cv
from .render import build, to_markdown
from .export import to_docx, to_pdf


@lru_cache(maxsize=1)
def _init():
    kb = load_kb(); atoms = build_atoms(kb)
    return kb, atoms, Retriever(atoms)


def run(offer: str, lang_override=None, out_prefix="/tmp/cv"):
    kb, atoms, retr = _init()
    job = analyze_offer(offer, lang_override)
    m = match(job, atoms, retr)
    cv, issues = generate_cv(kb, job, m)
    r = build(kb, cv, job["lang"])
    docx_p, pdf_p = f"{out_prefix}.docx", f"{out_prefix}.pdf"
    to_docx(r, docx_p); to_pdf(r, pdf_p)
    report = report_md(job, m, issues)
    return report, to_markdown(r), docx_p, pdf_p


def report_md(job, m, issues):
    j = lambda l: ", ".join(l) if l else "—"
    return (f"## Compatibilité : {m['score']}/100\n"
            f"**Poste** : {job.get('job_title','?')} · **Langue** : {job['lang']} · **Séniorité** : {job.get('seniority','?')}\n\n"
            f"- ✅ Exigences couvertes : {j(m['must_found'])}\n- ❌ Écarts réels (non revendiqués) : {j(m['must_missing'])}\n"
            f"- Souhaitables couverts : {j(m['nice_found'])}\n- Souhaitables manquants : {j(m['nice_missing'])}\n"
            f"- Mots-clés ATS couverts : {j(m['kw_found'])}\n- Mots-clés ATS non justifiés par ton CV : {j(m['kw_missing'])}\n\n"
            f"**Contrôle qualité** : " + ("✅ aucune affirmation hors base" if not issues else "⚠️ à relire :\n- " + "\n- ".join(issues)))