Karzan commited on
Commit
717cd71
1 Parent(s): 8593822

Update app.py

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