OAbdulalim/CodeGenerator
2
1from transformers import AutoTokenizer, AutoModelForCausalLM2import gradio as grad3codegen_tkn = AutoTokenizer.from_pretrained("Salesforce/codegen-350M-mono")4mdl = AutoModelForCausalLM.from_pretrained("Salesforce/codegen-350M-mono")5 6def codegen(intent):7# give input as text which reflects intent of the program.8 text = " write a function which takes 2 numbers as input and returns the larger of the two"9 input_ids = codegen_tkn(intent, return_tensors="pt").input_ids10 11 gen_ids = mdl.generate(input_ids, max_length=128)12 response = codegen_tkn.decode(gen_ids[0], skip_special_tokens=True)13 return response14 15output=grad.Textbox(lines=1, label="Generated Python Code", placeholder="")16inp=grad.Textbox(lines=1, label="Place your intent here")17grad.Interface(codegen, inputs=inp, outputs=output).launch()