Spaces:
Runtime error
Runtime error
Commit ·
3da38ba
1
Parent(s): 368af95
Updated prompt for document generation
Browse files54 unmodified lines5556575859606119 unmodified lines8182838485868788893 unmodified lines9394959697989954 unmodified lines@spaces.GPUdef generate_code(task_type: str, nl_input: str):if task_type == "NL to Java" or task_type == "End to End NL to C#":prompt = f"### Instruction:\n\n{nl_input} Write the solution in Java with proper indentation.\n\n### Response:\n\n"inputs = tokenizer(prompt, return_tensors="pt").to(model.device)outputs = model.generate(**inputs, max_new_tokens=128, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id)19 unmodified linesoutput= _clean_csharp_output(response)return format_code(output, language="cs")elif task_type=="Generate Documentation":prompt= f"### Instruction:\n\nGenerate documentation for the following code:\n\n{nl_input}\n\n### Response:\n\n/**"inputs=tokenizer(prompt, return_tensors="pt").to(model.device)output=model.generate(**inputs,max_new_tokens=200, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id)response = tokenizer.decode(output[0], skip_special_tokens=True).split("### Response:\n\n")[-1].strip()if not response.startswith("/**"):response = "/**" + response3 unmodified linesdemo = gr.Interface(fn=generate_code,inputs=[gr.Dropdown(label="Select Task", choices=["NL to Java", "Java to C#", "End to End NL to C#", "Generate Documentation"], value="NL to Java"),gr.Textbox(label="Input")],outputs=gr.Code(label="Generated Code"),54 unmodified lines5556575859606119 unmodified lines81828384858687883 unmodified lines9293949596979854 unmodified lines@spaces.GPUdef generate_code(task_type: str, nl_input: str):if task_type == "NL to Java" or task_type == "End to End NL to Java to C#":prompt = f"### Instruction:\n\n{nl_input} Write the solution in Java with proper indentation.\n\n### Response:\n\n"inputs = tokenizer(prompt, return_tensors="pt").to(model.device)outputs = model.generate(**inputs, max_new_tokens=128, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id)19 unmodified linesoutput= _clean_csharp_output(response)return format_code(output, language="cs")elif task_type=="Generate Documentation":# prompt= f"### Instruction:\n\nGenerate documentation for the following code:\n\n{nl_input}\n\n### Response:\n\n/**"prompt = f"### Instruction:\n\nWrite a documentation comment with @param and @return tags for the following method:\n\n{nl_input}\n\n### Response:\n\n/**" output=model.generate(**inputs,max_new_tokens=200, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id)response = tokenizer.decode(output[0], skip_special_tokens=True).split("### Response:\n\n")[-1].strip()if not response.startswith("/**"):response = "/**" + response3 unmodified linesdemo = gr.Interface(fn=generate_code,inputs=[gr.Dropdown(label="Select Task", choices=["NL to Java", "Java to C#", "End to End NL to Java to C#", "Generate Documentation"], value="NL to Java"),gr.Textbox(label="Input")],outputs=gr.Code(label="Generated Code"),
app.py+4-5