Spaces:
Runtime error
Runtime error
Update backend/analysis.py
Browse files- backend/analysis.py +50 -50
backend/analysis.py
CHANGED
|
@@ -1,51 +1,51 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
-
from langchain_groq import ChatGroq
|
| 4 |
-
from langchain_core.prompts import PromptTemplate
|
| 5 |
-
|
| 6 |
-
# Set up Groq API key
|
| 7 |
-
load_dotenv() # Load environment variables from .env file
|
| 8 |
-
os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY") # Set the Groq API key from environment variables
|
| 9 |
-
|
| 10 |
-
# Initialize the ChatGroq model with the specified model name
|
| 11 |
-
llm = ChatGroq(model_name="
|
| 12 |
-
|
| 13 |
-
def analyze_resume(full_resume, job_description):
|
| 14 |
-
# Template for analyzing the resume against the job description
|
| 15 |
-
template = """
|
| 16 |
-
You are an AI assistant specialized in resume analysis and recruitment. Analyze the given resume and compare it with the job description.
|
| 17 |
-
|
| 18 |
-
Example Response Structure:
|
| 19 |
-
|
| 20 |
-
**OVERVIEW**:
|
| 21 |
-
- **Match Percentage**: [Calculate overall match percentage between the resume and job description]
|
| 22 |
-
- **Matched Skills**: [List the skills in job description that match the resume]
|
| 23 |
-
- **Unmatched Skills**: [List the skills in the job description that are missing in the resume]
|
| 24 |
-
|
| 25 |
-
**DETAILED ANALYSIS**:
|
| 26 |
-
Provide a detailed analysis about:
|
| 27 |
-
1. Overall match percentage between the resume and job description
|
| 28 |
-
2. List of skills from the job description that match the resume
|
| 29 |
-
3. List of skills from the job description that are missing in the resume
|
| 30 |
-
|
| 31 |
-
**Additional Comments**:
|
| 32 |
-
Additional comments about the resume and suggestions for the recruiter or HR manager.
|
| 33 |
-
|
| 34 |
-
Resume: {resume}
|
| 35 |
-
Job Description: {job_description}
|
| 36 |
-
|
| 37 |
-
Analysis:
|
| 38 |
-
"""
|
| 39 |
-
prompt = PromptTemplate( # Create a prompt template with input variables
|
| 40 |
-
input_variables=["resume", "job_description"],
|
| 41 |
-
template=template
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
# Create a chain combining the prompt and the language model
|
| 45 |
-
chain = prompt | llm
|
| 46 |
-
|
| 47 |
-
# Invoke the chain with input data
|
| 48 |
-
response = chain.invoke({"resume": full_resume, "job_description": job_description})
|
| 49 |
-
|
| 50 |
-
# Return the content of the response
|
| 51 |
return response.content
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from langchain_groq import ChatGroq
|
| 4 |
+
from langchain_core.prompts import PromptTemplate
|
| 5 |
+
|
| 6 |
+
# Set up Groq API key
|
| 7 |
+
load_dotenv() # Load environment variables from .env file
|
| 8 |
+
os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY") # Set the Groq API key from environment variables
|
| 9 |
+
|
| 10 |
+
# Initialize the ChatGroq model with the specified model name
|
| 11 |
+
llm = ChatGroq(model_name="mistral-saba-24b")
|
| 12 |
+
|
| 13 |
+
def analyze_resume(full_resume, job_description):
|
| 14 |
+
# Template for analyzing the resume against the job description
|
| 15 |
+
template = """
|
| 16 |
+
You are an AI assistant specialized in resume analysis and recruitment. Analyze the given resume and compare it with the job description.
|
| 17 |
+
|
| 18 |
+
Example Response Structure:
|
| 19 |
+
|
| 20 |
+
**OVERVIEW**:
|
| 21 |
+
- **Match Percentage**: [Calculate overall match percentage between the resume and job description]
|
| 22 |
+
- **Matched Skills**: [List the skills in job description that match the resume]
|
| 23 |
+
- **Unmatched Skills**: [List the skills in the job description that are missing in the resume]
|
| 24 |
+
|
| 25 |
+
**DETAILED ANALYSIS**:
|
| 26 |
+
Provide a detailed analysis about:
|
| 27 |
+
1. Overall match percentage between the resume and job description
|
| 28 |
+
2. List of skills from the job description that match the resume
|
| 29 |
+
3. List of skills from the job description that are missing in the resume
|
| 30 |
+
|
| 31 |
+
**Additional Comments**:
|
| 32 |
+
Additional comments about the resume and suggestions for the recruiter or HR manager.
|
| 33 |
+
|
| 34 |
+
Resume: {resume}
|
| 35 |
+
Job Description: {job_description}
|
| 36 |
+
|
| 37 |
+
Analysis:
|
| 38 |
+
"""
|
| 39 |
+
prompt = PromptTemplate( # Create a prompt template with input variables
|
| 40 |
+
input_variables=["resume", "job_description"],
|
| 41 |
+
template=template
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Create a chain combining the prompt and the language model
|
| 45 |
+
chain = prompt | llm
|
| 46 |
+
|
| 47 |
+
# Invoke the chain with input data
|
| 48 |
+
response = chain.invoke({"resume": full_resume, "job_description": job_description})
|
| 49 |
+
|
| 50 |
+
# Return the content of the response
|
| 51 |
return response.content
|