nikhedward commited on
Commit
8eb2613
β€’
1 Parent(s): 39c1f3e

added new function

Browse files
Files changed (1) hide show
  1. app.py +31 -7
app.py CHANGED
@@ -1,4 +1,7 @@
1
  import gradio as gr
 
 
 
2
  title = "Text Summarizer πŸ“"
3
 
4
 
@@ -36,11 +39,32 @@ Abstractive Summarization: The abstractive approach involves rephrasing the comp
36
  '''
37
 
38
 
39
- interface = gr.Interface.load("huggingface/nikhedward/bart-large-cnn-finetuned-multi-news",
40
- title = title,
41
- description = desc,
42
- theme = "peach",
43
- examples = sample_texts,
44
- inputs = gr.inputs.Textbox(lines = 10, label="Input Text"))
45
 
46
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import transformers
3
+ from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
4
+
5
  title = "Text Summarizer πŸ“"
6
 
7
 
 
39
  '''
40
 
41
 
 
 
 
 
 
 
42
 
43
+ model_name = 'facebook/bart-large-cnn'
44
+ tokenizer = BartTokenizer.from_pretrained(model_name)
45
+ model = BartForConditionalGeneration.from_pretrained(model_name)
46
+
47
+ def summarize(inp):
48
+ inp = inp.replace('\n','')
49
+ inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024)
50
+ summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True)
51
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
52
+ return summary
53
+
54
+ interface = gr.Interface(fn=summarize, inputs=gr.inputs.Textbox(lines=10, label="Input Text"), description = desc, theme = "peach", examples = sample_texts, title = title outputs="text")
55
+
56
+ interface.launch()
57
+
58
+
59
+
60
+
61
+
62
+
63
+ #interface = gr.Interface.load("huggingface/nikhedward/bart-large-cnn-finetuned-multi-news",
64
+ #title = title,
65
+ #description = desc,
66
+ #theme = "peach",
67
+ #examples = sample_texts,
68
+ #inputs = gr.inputs.Textbox(lines = 10, label="Input Text"))
69
+
70
+ #interface.launch()