function_summarizer / code_summarizer.py
HemaSowjanya's picture
Create code_summarizer.py
8c56de2 verified
raw
history blame
667 Bytes
from transformers import RobertaTokenizer, T5ForConditionalGeneration
def query(user_prompt):
tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-base-multi-sum')
model = T5ForConditionalGeneration.from_pretrained('Salesforce/codet5-base-multi-sum')
prompt=f"""<|system|>\nYou are an intelligent chatbot and an expert in python programming language.
Your task is to understand and summarize</s>\n<|user|>\n {user_prompt}\n<|assistant|>"""
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
generated_ids = model.generate(input_ids, max_length=20)
return tokenizer.decode(generated_ids[0], skip_special_tokens=True)