Inference
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import time
import torch
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = AutoModelForSequenceClassification.from_pretrained("AquilaX-AI/Review").to(device)
tokenizer = AutoTokenizer.from_pretrained("AquilaX-AI/Review")
partial_code = "if (userInput.length > 255) { return; }"
cwe_id = "CWE-22"
cwe_name = "Improper Limitation of a Pathname to a Restricted Directory"
affected_line = "42"
file_name = "utils/inputValidator.js"
org_id = "12345"
start = time.time()
prompt = f"""partial_code: {partial_code} , cwe_id: {cwe_id} , cwe_name: {cwe_name}, affected_line: {affected_line},file_name: {file_name}, org_id: {org_id}"""
inputs = tokenizer(prompt, return_tensors="pt").to(device)
with torch.no_grad():
logits = model(**inputs).logits
predicted_class_id = logits.argmax().item()
predicted_class = model.config.id2label[predicted_class_id]
print(predicted_class)
print(time.time() - start)