File size: 1,318 Bytes
2464816 | 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 | import json
from huggingface_hub import hf_hub_download
from llama_cpp import Llama
from cv_prompt import get_cv_prompt, cv_sections_data
from ocr_extractor import process_file
def load_model():
model_path = hf_hub_download("TheBloke/Mistral-7B-Instruct-v0.2-GGUF", filename="mistral-7b-instruct-v0.2.Q4_K_M.gguf")
return Llama(model_path=model_path, n_ctx=32768, n_gpu_layers=2)
llm = load_model()
def detect_cv_sections_and_score(text):
prompt = get_cv_prompt(text)
response = llm(prompt, max_tokens=500)
response_text = response['choices'][0]['text']
json_start = response_text.find('{')
json_end = response_text.rfind('}') + 1
json_str = response_text[json_start:json_end]
try:
detected_sections = json.loads(json_str)
present_sections = detected_sections.get("present_sections", [])
score_sections = sum(cv_sections_data["sections"].get(section, 0) for section in present_sections)
result = {
"present_sections": present_sections,
"score_sections": score_sections
}
return result
except json.JSONDecodeError:
return {"present_sections": [], "score_sections": 0}
def analyze_cv(file_path):
text = process_file(file_path, 'ocr_weights.json')
return detect_cv_sections_and_score(text) |