import time import gradio as gr from transformers import AutoTokenizer, AutoModelForSequenceClassification import torch MODEL_ID = "abnetsisaynew/joblink-match-scorer" # ── Model loading ───────────────────────────────────────────────────────────── _startup_time = time.time() print(f"⏳ Loading model: {MODEL_ID} ...") _tokenizer = AutoTokenizer.from_pretrained(MODEL_ID) _model = AutoModelForSequenceClassification.from_pretrained( MODEL_ID, num_labels=1, problem_type="regression", ignore_mismatched_sizes=True, ) _model.eval().float() _load_time = time.time() - _startup_time print(f"✅ Model loaded in {_load_time:.1f}s!") # ── Prediction function ─────────────────────────────────────────────────────── def compute_score(text: str): if not text or not text.strip(): return {"score": 0.0} text = text.strip()[:4096] tokens = _tokenizer( text, truncation=True, padding="max_length", max_length=512, return_tensors="pt" ) with torch.no_grad(): score = _model(**tokens).logits.squeeze().item() return {"score": round(float(max(0.0, min(1.0, score))), 4)} custom_css = ''' .gradio-container { font-family: 'Inter', sans-serif !important; } .header-text { text-align: center; color: var(--color-accent) !important; font-weight: 800; margin-bottom: 0.5rem; font-size: 2.8rem !important; letter-spacing: -0.025em; } .sub-text { text-align: center; color: var(--body-text-color-subdued) !important; margin-bottom: 2rem; font-size: 1.2rem !important; } .score-box { border-radius: 12px; padding: 1.5rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); } ''' with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="slate"), css=custom_css, title="JobLink Matcher") as demo: gr.Markdown("
State-of-the-art semantic matching powered by fine-tuned DeBERTa-v3.
") with gr.Row(): with gr.Column(scale=2): gr.Markdown("### 📝 Job Description & Candidate CV") input_text = gr.Textbox( show_label=False, placeholder="JOB: Senior Software Engineer... [SEP] CANDIDATE: BSc Computer Science...", lines=12, container=False ) submit_btn = gr.Button("🚀 Compute Match Score", variant="primary", size="lg") with gr.Column(scale=1): gr.Markdown("### 🎯 Match Score Result") with gr.Group(elem_classes="score-box"): output_json = gr.JSON(label="Result JSON") gr.Markdown( """