HemaSowjanya commited on
Commit
8c56de2
1 Parent(s): da1fcf4

Create code_summarizer.py

Browse files
Files changed (1) hide show
  1. code_summarizer.py +11 -0
code_summarizer.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import RobertaTokenizer, T5ForConditionalGeneration
2
+
3
+ def query(user_prompt):
4
+ tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-base-multi-sum')
5
+ model = T5ForConditionalGeneration.from_pretrained('Salesforce/codet5-base-multi-sum')
6
+ prompt=f"""<|system|>\nYou are an intelligent chatbot and an expert in python programming language.
7
+ Your task is to understand and summarize</s>\n<|user|>\n {user_prompt}\n<|assistant|>"""
8
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids
9
+
10
+ generated_ids = model.generate(input_ids, max_length=20)
11
+ return tokenizer.decode(generated_ids[0], skip_special_tokens=True)