Funbi commited on
Commit
ae3af40
·
1 Parent(s): 6dd70de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -11,50 +11,55 @@ def query(payload):
11
 
12
 
13
  def summarize(input_text):
14
- max_chunk = 500
 
 
 
 
 
15
 
16
- input_text = input_text.replace('.', '.<eos>')
17
 
18
- input_text = input_text.replace('?', '?<eos>')
19
 
20
- input_text = input_text.replace('!', '!<eos>')
21
 
22
- sentences = input_text.split('<eos>')
23
 
24
- current_chunk = 0
25
 
26
- chunks = []
27
 
28
- for sentence in sentences:
29
 
30
- if len(chunks) == current_chunk + 1:
31
 
32
- if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk:
33
 
34
- chunks[current_chunk].extend(sentence.split(' '))
35
 
36
- else:
37
 
38
- current_chunk += 1
39
 
40
- chunks.append(sentence.split(' '))
41
 
42
- else:
43
 
44
- print(current_chunk)
45
 
46
- chunks.append(sentence.split(' '))
47
 
48
 
49
- for chunk_id in range(len(chunks)):
50
 
51
- chunks[chunk_id] = ' '.join(chunks[chunk_id])
52
 
53
 
54
- res = query({"inputs":chunks})
55
 
56
 
57
- text = ' '.join([summ['summary_text'] for summ in res])
58
 
59
  return text
60
 
 
11
 
12
 
13
  def summarize(input_text):
14
+ lister= input_text.split(" ")
15
+ word_lenght = len(lister)
16
+ if word_lenght < 50:
17
+ text= "Oops! It looks like your sentence is too short to summarize."
18
+ else:
19
+ max_chunk = 500
20
 
21
+ input_text = input_text.replace('.', '.<eos>')
22
 
23
+ input_text = input_text.replace('?', '?<eos>')
24
 
25
+ input_text = input_text.replace('!', '!<eos>')
26
 
27
+ sentences = input_text.split('<eos>')
28
 
29
+ current_chunk = 0
30
 
31
+ chunks = []
32
 
33
+ for sentence in sentences:
34
 
35
+ if len(chunks) == current_chunk + 1:
36
 
37
+ if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk:
38
 
39
+ chunks[current_chunk].extend(sentence.split(' '))
40
 
41
+ else:
42
 
43
+ current_chunk += 1
44
 
45
+ chunks.append(sentence.split(' '))
46
 
47
+ else:
48
 
49
+ print(current_chunk)
50
 
51
+ chunks.append(sentence.split(' '))
52
 
53
 
54
+ for chunk_id in range(len(chunks)):
55
 
56
+ chunks[chunk_id] = ' '.join(chunks[chunk_id])
57
 
58
 
59
+ res = query({"inputs":chunks})
60
 
61
 
62
+ text = ' '.join([summ['summary_text'] for summ in res])
63
 
64
  return text
65