Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,28 @@ from transformers import RobertaTokenizer, T5ForConditionalGeneration
|
|
3 |
tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-small')
|
4 |
model = T5ForConditionalGeneration.from_pretrained('Salesforce/codet5-small')
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
input_ids = tokenizer(text, return_tensors="pt").input_ids
|
8 |
|
9 |
-
|
10 |
-
generated_ids =
|
|
|
11 |
print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
|
12 |
-
# this prints "user: {user.name}"
|
|
|
3 |
tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-small')
|
4 |
model = T5ForConditionalGeneration.from_pretrained('Salesforce/codet5-small')
|
5 |
|
6 |
+
# provide code snippet as input
|
7 |
+
text = """ public static void main(String[] args) {
|
8 |
+
|
9 |
+
int num = 29;
|
10 |
+
boolean flag = false;
|
11 |
+
for (int i = 2; i <= num / 2; ++i) {
|
12 |
+
// condition for nonprime number
|
13 |
+
if (num % i == 0) {
|
14 |
+
flag = true;
|
15 |
+
break;
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
if (!flag)
|
20 |
+
System.out.println(num + " is a prime number.");
|
21 |
+
else
|
22 |
+
System.out.println(num + " is not a prime number.");
|
23 |
+
} """
|
24 |
+
|
25 |
input_ids = tokenizer(text, return_tensors="pt").input_ids
|
26 |
|
27 |
+
input_ids = codeT5_tkn(text, return_tensors="pt").input_ids
|
28 |
+
generated_ids = mdl.generate(input_ids, max_length=20)
|
29 |
+
|
30 |
print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
|
|