wiraindrak commited on
Commit
0fd3cfb
·
1 Parent(s): 664a7e2

Create new file

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import T5Tokenizer, T5Model, T5ForConditionalGeneration
2
+
3
+ tokenizer_t5 = T5Tokenizer.from_pretrained("panggi/t5-base-indonesian-summarization-cased")
4
+ model_t5 = T5ForConditionalGeneration.from_pretrained("panggi/t5-base-indonesian-summarization-cased")
5
+
6
+ def summ_t5(text):
7
+ input_ids = tokenizer.encode(text, return_tensors='pt')
8
+ summary_ids = model_.generate(input_ids,
9
+ max_length=100,
10
+ num_beams=2,
11
+ repetition_penalty=2.5,
12
+ length_penalty=1.0,
13
+ early_stopping=True,
14
+ no_repeat_ngram_size=2,
15
+ use_cache=True)
16
+ summary_text = tokenizer_t5.decode(summary_ids[0], skip_special_tokens=True)
17
+ return summary_text
18
+
19
+ sentiment_demo = gr.Interface(
20
+ fn=summ_t5,
21
+ inputs="text",
22
+ outputs="text")
23
+
24
+ if __name__ == "__main__":
25
+ Parallel(summ_demo,
26
+ inputs=gr.Textbox(lines=10, label="Input Text", placeholder="Enter article here..."),
27
+ title="Summary of Summarizer - Indonesia",
28
+ examples=examples).launch()