saifeddinemk commited on
Commit
91207a8
·
1 Parent(s): 8c57102
Files changed (2) hide show
  1. app.py +55 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ from peft import PeftModel, PeftConfig
5
+
6
+ # Initialize the FastAPI app
7
+ app = FastAPI()
8
+
9
+ # Load model and tokenizer once at startup
10
+ base_model_name = "akjindal53244/Llama-3.1-Storm-8B"
11
+ peft_model_id = "LlamaFactoryAI/cv-job-description-matching"
12
+
13
+ base_model = AutoModelForCausalLM.from_pretrained(base_model_name)
14
+ tokenizer = AutoTokenizer.from_pretrained(base_model_name)
15
+ config = PeftConfig.from_pretrained(peft_model_id)
16
+ model = PeftModel.from_pretrained(base_model, peft_model_id)
17
+
18
+ # Define request model
19
+ class AnalysisRequest(BaseModel):
20
+ cv: str
21
+ job_description: str
22
+
23
+ @app.post("/analyze")
24
+ async def analyze(request: AnalysisRequest):
25
+ try:
26
+ # Prepare input text with formatted message
27
+ system_prompt = """
28
+ You are an advanced AI model designed to analyze the compatibility between a CV and a job description. You will receive a CV and a job description. Your task is to output a structured JSON format that includes the following:
29
+
30
+ 1. matching_analysis: Analyze the CV against the job description to identify key strengths and gaps.
31
+ 2. description: Summarize the relevance of the CV to the job description in a few concise sentences.
32
+ 3. score: Provide a numerical compatibility score (0-100) based on qualifications, skills, and experience.
33
+ 4. recommendation: Suggest actions for the candidate to improve their match or readiness for the role.
34
+
35
+ Your output must be in JSON format as follows:
36
+ {
37
+ "matching_analysis": "Your detailed analysis here.",
38
+ "description": "A brief summary here.",
39
+ "score": 85,
40
+ "recommendation": "Your suggestions here."
41
+ }
42
+ """
43
+ user_input = f"<CV> {request.cv} </CV>\n<job_description> {request.job_description} </job_description>"
44
+ input_text = system_prompt + user_input
45
+
46
+ # Tokenize and generate response
47
+ inputs = tokenizer(input_text, return_tensors="pt")
48
+ outputs = model.generate(**inputs, max_new_tokens=128)
49
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
50
+
51
+ return {"analysis": generated_text}
52
+
53
+ except Exception as e:
54
+ raise HTTPException(status_code=500, detail=str(e))
55
+
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ transformers
4
+ peft
5
+ torch
6
+ pydantic
7
+ torchvision
8
+ torchaudio