Spaces:
Running
Running
Download app/utils/classifier.py from fallingbody/Mockai: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/spaces/fallingbody/Mockai/resolve/main/app/utils/classifier.py
- Command line
-
hf download hf://spaces/fallingbody/Mockai/app/utils/classifier.py
-
curl -L -o classifier.py https://huggingface.co/spaces/fallingbody/Mockai/resolve/main/app/utils/classifier.py
1.95 kB
| import os | |
| from google import genai | |
| from google.genai import types | |
| from app.core.logger import get_logger | |
| logger = get_logger(__name__) | |
| def classify_candidate(resume_text: str) -> str: | |
| """ | |
| Classifies a candidate's experience level based on their resume text. | |
| Args: | |
| resume_text: The text content of the candidate's resume. | |
| Returns: | |
| A string indicating the level: 'beginner', 'intermediate', or 'advanced'. | |
| """ | |
| prompt = f""" | |
| Analyze the following resume text and classify the candidate's experience level. | |
| Your response must be one of these three words ONLY: 'beginner', 'intermediate', 'advanced'. | |
| - 'beginner': 0-2 years of experience, familiar with concepts but limited practical application. | |
| - 'intermediate': 2-5 years of experience, solid practical skills, has worked on multiple projects. | |
| - 'advanced': 5+ years of experience, deep expertise, leadership, or architectural skills. | |
| Do not provide any explanation or other text. | |
| Resume Text: | |
| --- | |
| {resume_text} | |
| --- | |
| Classification:""" | |
| try: | |
| api_key = os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY") | |
| if not api_key: | |
| logger.warning("GEMINI_API_KEY is not configured. Falling back to intermediate level.") | |
| return "intermediate" | |
| client = genai.Client(api_key=api_key) | |
| from app.core.config import settings | |
| model_name = getattr(settings, "GEMINI_MODEL", "gemini-3.1-flash-lite") | |
| response = client.models.generate_content( | |
| model=model_name, | |
| contents=prompt, | |
| config=types.GenerateContentConfig(temperature=0.1) | |
| ) | |
| level = response.text.strip().lower().replace("'", "") | |
| return level if level in ['beginner', 'intermediate', 'advanced'] else 'intermediate' | |
| except Exception as e: | |
| logger.error("Error during candidate classification", extra={"error": str(e)}) | |
| return 'intermediate' | |