abdullahashraf122's picture
feat: publish NL2Py v2 English-to-Python neural code translator & Gradio pipeline
969d253 verified
Raw History Blame Contribute Delete
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()