Amit29sonawane commited on
Commit
c77b794
·
1 Parent(s): ddb23ec

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import transformers
3
+ from transformers import BartTokenizer, BartForConditionalGeneration
4
+
5
+ model_name = 'facebook/bart-large-cnn'
6
+ tokenizer = BartTokenizer.from_pretrained(model_name)
7
+ model = BartForConditionalGeneration.from_pretrained(model_name)
8
+
9
+ def summarize(inp):
10
+ inp = inp.replace('\n','')
11
+ inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024)
12
+ summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True)
13
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
14
+ return summary
15
+
16
+ gr.Interface(fn=summarize, inputs=gr.components.Textbox(lines=7, label="Input Text"), outputs="text").launch()