Download app.py from abdullahashraf122/nl2py-v2-code-translator: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/abdullahashraf122/nl2py-v2-code-translator/resolve/main/app.py
- Command line
-
hf download hf://abdullahashraf122/nl2py-v2-code-translator/app.py
-
curl -L -o app.py https://huggingface.co/abdullahashraf122/nl2py-v2-code-translator/resolve/main/app.py
1.03 kB
| import gradio as gr | |
| from transformers import pipeline | |
| MODEL_NAME = "t5-small" | |
| PREFIX = "translate English to Python: " | |
| def generate_python_code(english_command): | |
| if not english_command: | |
| return "" | |
| try: | |
| # Prompt translation heuristic demo | |
| pipe = pipeline("text2text-generation", model=MODEL_NAME) | |
| res = pipe(PREFIX + english_command, max_length=256) | |
| return res[0]["generated_text"] | |
| except Exception as e: | |
| return f"# Execution note: {e}" | |
| demo = gr.Interface( | |
| fn=generate_python_code, | |
| inputs=gr.Textbox(lines=3, label="English Instruction", placeholder="e.g. read csv into pandas and filter column x > 5"), | |
| outputs=gr.Code(language="python", label="Generated Python Code"), | |
| title="NL2Py v2: English-to-Python Neural Code Translator", | |
| description="Fine-tuned T5-small seq2seq transformer for automated Python code synthesis.", | |
| theme=gr.themes.Soft(primary_hue="emerald") | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |