aliarsal1512 commited on
Commit
1f790da
·
verified ·
1 Parent(s): 3d9e5a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, T5ForConditionalGeneration
2
+ import gradio as gr
3
+
4
+ model_name = "SEBIS/code_trans_t5_base_code_comment_generation_java"
5
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
6
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
7
+
8
+ def generate_comment(code: str):
9
+ inputs = tokenizer(code, return_tensors="pt")
10
+ outputs = model.generate(**inputs, max_length=128)
11
+ comment = tokenizer.decode(outputs[0], skip_special_tokens=True)
12
+ return comment
13
+
14
+ iface = gr.Interface(fn=generate_comment, inputs="text", outputs="text")
15
+ iface.launch()