Spaces:
Sleeping
Sleeping
File size: 1,317 Bytes
ffb6d48 80ed1fd ffb6d48 80ed1fd ffb6d48 b5ac3f0 ffb6d48 b5ac3f0 ffb6d48 b5ac3f0 7bd332d b0c8c8c fb6c4a2 5560955 b0c8c8c ffb6d48 5560955 ffb6d48 cda75bc 8756a40 ffb6d48 |
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 |
from transformers import AutoTokenizer, AutoModelForCausalLM
import os
import torch
# Check if CUDA is available for faster inference
device = 'cuda' if torch.cuda.is_available() else 'cpu'
# Load the tokenizer and model once, outside of the function
huggingface_token = os.environ.get("KEY2")
tokenizer = AutoTokenizer.from_pretrained(
"meta-llama/Llama-3.2-1B",
use_auth_token=huggingface_token
)
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.2-1B",
use_auth_token=huggingface_token
).to(device)
def modelFeedback(ats_score, resume_data, job_description):
"""
"""
try:
# Tokenize the input
input_ids = tokenizer.encode(input_prompt, return_tensors="pt").to(device)
# Disable gradient calculation for faster inference
with torch.no_grad():
# Generate the output
output = model.generate(
input_ids,
max_length=1500,
temperature=0.01,
pad_token_id=tokenizer.eos_token_id # Ensure padding works properly
)
# Decode the output
response_text = tokenizer.decode(output[0], skip_special_tokens=True)
return response_text
except Exception as e:
print(f"Error during generation: {e}") |