Spaces:
Runtime error
Runtime error
Download agents/code_modifier.py from hugging2021/CodeFixPro: direct link, hf CLI and curl.
- Browser
- Download file 722 Bytes
-
https://huggingface.co/spaces/hugging2021/CodeFixPro/resolve/52bd97a3fc927725bfb4656b37191dd632fb338f/agents/code_modifier.py
- Command line
-
hf download hf://spaces/hugging2021/CodeFixPro@52bd97a3fc927725bfb4656b37191dd632fb338f/agents/code_modifier.py
-
curl -L -o code_modifier.py https://huggingface.co/spaces/hugging2021/CodeFixPro/resolve/52bd97a3fc927725bfb4656b37191dd632fb338f/agents/code_modifier.py
722 Bytes
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline | |
| # Load the same CodeT5 model | |
| tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-base") | |
| model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-base") | |
| modifier_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer) | |
| def modify_code(code: str, instruction: str) -> str: | |
| """ | |
| Modifies code based on user's instruction prompt. | |
| """ | |
| prompt = f"Instruction: {instruction}\nCode:\n{code}\nModified Code:" | |
| try: | |
| result = modifier_pipeline(prompt, max_length=256)[0]["generated_text"] | |
| return result.strip() | |
| except Exception as e: | |
| return f"Error during modification: {e}" | |