edemgold commited on
Commit
e8e2eea
1 Parent(s): 29cb32c

Added block by block summarizing

Browse files

Broke longer block of text into smaller chunks for the model to summarize

Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -4,13 +4,17 @@ import gradio as gr
4
  #model
5
  model = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") #model="sshleifer/distilbart-cnn-12-6")
6
 
7
- def func(article):
8
- article_length = article.split()
9
- words = len(article_length)
10
- if words>900:
11
- return "Oops!😰, I can't summarize text that long, please shorten the text🥺"
12
- else:
13
- return (model(article, max_length=100, do_sample=False))
 
 
 
 
14
 
15
  app = gr.Interface(fn=func, inputs="textbox", outputs="textbox", title="InfluencerAI-Summarizer")
16
  app.launch()
 
4
  #model
5
  model = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") #model="sshleifer/distilbart-cnn-12-6")
6
 
7
+ def func(Text):
8
+ words = Text.split()
9
+ grouped_words = [' '.join(words[i: i + 300]) for i in range(0, len(words), 300)]
10
+ summary_list = []
11
+ for i in grouped_words:
12
+ y = model(i, max_length=80, do_sample=False)
13
+ summary_list.append(y)
14
+ final_summary = ','.join(str(v) for v in summary_list)
15
+ return final_summary
16
+
17
+ import gradio as gr
18
 
19
  app = gr.Interface(fn=func, inputs="textbox", outputs="textbox", title="InfluencerAI-Summarizer")
20
  app.launch()