Spaces:
Running
Running
Update agents/error_fixer.py
Browse files- agents/error_fixer.py +8 -9
agents/error_fixer.py
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
-
from transformers import AutoTokenizer,
|
2 |
|
3 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
4 |
-
model =
|
5 |
-
fix_pipeline = pipeline("
|
6 |
|
7 |
def fix_code(code: str) -> str:
|
8 |
-
prompt = f"""
|
9 |
try:
|
10 |
-
result = fix_pipeline(prompt, max_length=256
|
11 |
-
|
12 |
-
return result.split("# Fixed Code:")[-1].strip()
|
13 |
except Exception as e:
|
14 |
-
return f"Error during fixing: {e}"
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
2 |
|
3 |
+
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-small")
|
4 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-small")
|
5 |
+
fix_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
6 |
|
7 |
def fix_code(code: str) -> str:
|
8 |
+
prompt = f"""The following Python code has some bugs. Fix the code:\n\n{code}\n\nCorrected version:"""
|
9 |
try:
|
10 |
+
result = fix_pipeline(prompt, max_length=256)[0]["generated_text"]
|
11 |
+
return result.strip()
|
|
|
12 |
except Exception as e:
|
13 |
+
return f"Error during fixing: {e}"
|