Spaces:
Sleeping
Sleeping
Download app.py from m0a9/job_classifier: direct link, hf CLI and curl.
- Browser
- Download file 2.53 kB
-
https://huggingface.co/spaces/m0a9/job_classifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/m0a9/job_classifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/m0a9/job_classifier/resolve/main/app.py
2.53 kB
| #!/usr/bin/env python3 | |
| """Simple demo app for years-of-experience prediction.""" | |
| from __future__ import annotations | |
| from pathlib import Path | |
| import gradio as gr | |
| import joblib | |
| from experience_classifier import CLASS_LABELS, MODEL_PATH, predict_row_hybrid | |
| ROOT = Path(__file__).resolve().parent | |
| def class_to_years(level: int) -> str: | |
| mapping = { | |
| 1: "0-2 years", | |
| 2: "3-5 years", | |
| 3: "6-15 years", | |
| 4: "16+ years", | |
| } | |
| return mapping.get(level, "Unknown") | |
| def load_bundle() -> tuple: | |
| if not MODEL_PATH.exists(): | |
| raise FileNotFoundError( | |
| f"Model file not found at {MODEL_PATH}. " | |
| "Run `python experience_classifier.py train` first." | |
| ) | |
| bundle = joblib.load(MODEL_PATH) | |
| return bundle["vectorizer"], bundle["model"] | |
| VEC, CLF = load_bundle() | |
| def predict_required_experience(job_information: str) -> str: | |
| text = (job_information or "").strip() | |
| if not text: | |
| return "Please paste the job information first." | |
| row = { | |
| "OrigJobTitle": "", | |
| "JobDescription": text, | |
| } | |
| pred = predict_row_hybrid(row, VEC, CLF) | |
| level = int(pred["experience_level"]) | |
| years_range = class_to_years(level) | |
| source = pred.get("experience_source", "unknown") | |
| confidence = float(pred.get("experience_confidence", 0.0)) | |
| evidence = pred.get("experience_evidence") | |
| min_years = pred.get("experience_min_years") | |
| max_years = pred.get("experience_max_years") | |
| lines = [ | |
| f"Estimated required experience: {years_range}", | |
| f"Predicted class: {level} ({CLASS_LABELS.get(level, 'unknown')})", | |
| f"Source: {source} | Confidence: {confidence:.2f}", | |
| ] | |
| if min_years is not None: | |
| if max_years is not None and max_years != min_years: | |
| lines.append(f"Extracted years from text: {min_years:.1f}-{max_years:.1f}") | |
| else: | |
| lines.append(f"Extracted years from text: {min_years:.1f}") | |
| if evidence: | |
| lines.append(f"Evidence: {evidence}") | |
| return "\n".join(lines) | |
| demo = gr.Interface( | |
| fn=predict_required_experience, | |
| inputs=gr.Textbox( | |
| lines=16, | |
| label="Job Information", | |
| placeholder="Paste the full job Information here...", | |
| ), | |
| outputs=gr.Textbox(lines=8, label="Predicted Experience"), | |
| title="Job Experience Requirement Predictor", | |
| description="Paste a job post and get estimated required years of experience.", | |
| flagging_mode="never", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |