Spaces:
Running

File size: 1,953 Bytes
4b10b93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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'