Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,50 +11,55 @@ def query(payload):
|
|
11 |
|
12 |
|
13 |
def summarize(input_text):
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
23 |
|
24 |
-
|
25 |
|
26 |
-
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
|
32 |
-
|
33 |
|
34 |
-
|
35 |
|
36 |
-
|
37 |
|
38 |
-
|
39 |
|
40 |
-
|
41 |
|
42 |
-
|
43 |
|
44 |
-
|
45 |
|
46 |
-
|
47 |
|
48 |
|
49 |
-
|
50 |
|
51 |
-
|
52 |
|
53 |
|
54 |
-
|
55 |
|
56 |
|
57 |
-
|
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 |
|