Spaces:
Sleeping
Sleeping
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer | |
model_name = "Salesforce/codet5-base" | |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
# More complex C# code snippet | |
code_snippet = """ | |
// This class demonstrates a simple calculator program | |
public class Calculator { | |
// Adds two integers | |
public int Add(int a, int b) { | |
return a + b; | |
} | |
// Subtracts second integer from first | |
public int Subtract(int a, int b) { | |
return a - b; | |
} | |
// Multiplies two integers | |
public int Multiply(int a, int b) { | |
return a * b; | |
} | |
// Divides first integer by second | |
// Throws DivideByZeroException if b is zero | |
public int Divide(int a, int b) { | |
if (b == 0) { | |
throw new DivideByZeroException("Division by zero is not allowed."); | |
} | |
return a / b; | |
} | |
} | |
""" | |
inputs = tokenizer(code_snippet, return_tensors="pt") | |
outputs = model.generate(**inputs, max_new_tokens=100) | |
review = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
print("Code Review:", review) | |