bainskarman commited on
Commit
8756a40
·
verified ·
1 Parent(s): f2f95fe

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +22 -40
model.py CHANGED
@@ -1,28 +1,10 @@
1
- import csv
2
- import io
3
- import os
4
- import requests
5
- import json
6
- import html # For escaping HTML characters
7
- from bs4 import BeautifulSoup
8
- from openai import OpenAI
9
 
10
- # Initialize OpenAI API with Nvidia's Llama 3.1 70b nemotron model
11
- client = OpenAI(
12
- base_url="https://integrate.api.nvidia.com/v1",
13
- api_key=os.environ.get("KEY")
14
- )
15
-
16
- def clean_text_output(text):
17
  """
18
- Cleans the output to handle HTML characters and unwanted tags.
19
  """
20
- text = html.unescape(text) # Unescape HTML entities
21
- soup = BeautifulSoup(text, 'html.parser') # Use BeautifulSoup to handle HTML tags
22
- cleaned_text = soup.get_text(separator="\n").strip() # Remove tags and handle newlines
23
- return cleaned_text
24
-
25
- def modelFeedback(ats_score, resume_data, job_description):
26
  input_prompt = f"""
27
  You are now an ATS Score analyzer and given ATS Score is {int(ats_score * 100)}%.
28
  Your task is to provide a comprehensive review and feedback based on the ATS score.
@@ -79,25 +61,25 @@ def modelFeedback(ats_score, resume_data, job_description):
79
  IMPORTANT: The output should be as normal organised text not in any other format (don't give markdown text) and focus more on resume matching part that general resume review.
80
  """
81
 
 
 
 
 
 
 
82
 
 
83
  try:
84
- # Generate response using the OpenAI API
85
- response = client.chat.completions.create(
86
- model="nvidia/llama-3.1-nemotron-70b-instruct", # Using Llama 3.1 70b
87
- messages=[
88
- {"role": "user", "content": input_prompt}
89
- ],
90
- temperature=0.01, # Lowering temperature for precise output
91
- top_p=0.7, # Prioritize high-probability tokens
92
- max_tokens=1500, # Allow longer content
93
  )
94
-
95
- # Extract and clean the response
96
- feedback_text = response.choices[0].message.content.strip() # Corrected line
97
- cleaned_feedback = clean_text_output(feedback_text)
98
-
99
  return cleaned_feedback
100
-
101
- except requests.exceptions.RequestException as e:
102
- print(f"API request failed: {str(e)}")
103
- return "Error: Unable to generate feedback."
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import torch
 
 
 
 
 
 
3
 
4
+ def modelFeedback_direct(ats_score, resume_data, job_description):
 
 
 
 
 
 
5
  """
6
+ Generate ATS feedback by loading model and tokenizer directly.
7
  """
 
 
 
 
 
 
8
  input_prompt = f"""
9
  You are now an ATS Score analyzer and given ATS Score is {int(ats_score * 100)}%.
10
  Your task is to provide a comprehensive review and feedback based on the ATS score.
 
61
  IMPORTANT: The output should be as normal organised text not in any other format (don't give markdown text) and focus more on resume matching part that general resume review.
62
  """
63
 
64
+ # Load tokenizer and model
65
+ tokenizer = AutoTokenizer.from_pretrained("nvidia/Llama-3.1-Nemotron-70B-Instruct-HF")
66
+ model = AutoModelForCausalLM.from_pretrained("nvidia/Llama-3.1-Nemotron-70B-Instruct-HF")
67
+
68
+ # Tokenize the input
69
+ inputs = tokenizer.encode(input_prompt, return_tensors="pt")
70
 
71
+ # Generate the response
72
  try:
73
+ outputs = model.generate(
74
+ inputs,
75
+ max_length=1500,
76
+ temperature=0.01,
77
+ top_p=0.7,
78
+ pad_token_id=tokenizer.eos_token_id
 
 
 
79
  )
80
+ response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
81
+ cleaned_feedback = clean_text_output(response_text)
 
 
 
82
  return cleaned_feedback
83
+ except Exception as e:
84
+ print(f"Model generation error: {e}")
85
+ return "Error: Unable to generate feedback."