Spaces:
Running
Running
File size: 608 Bytes
18e62cf 60370a2 18e62cf 60370a2 18e62cf 60370a2 18e62cf 60370a2 18e62cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
# Load CodeT5 model (public and free)
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-base")
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-base")
code_fix_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
def fix_code(code: str) -> str:
prompt = f"Fix the following code:\n{code}"
try:
result = code_fix_pipeline(prompt, max_length=256)[0]["generated_text"]
return result.strip()
except Exception as e:
return f"Error during fixing: {e}"
|