Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,46 +6,22 @@ def load_summarizer():
|
|
6 |
model = pipeline("summarization", model="google/bigbird-pegasus-large-bigpatent")
|
7 |
return model
|
8 |
|
9 |
-
|
10 |
-
def generate_chunks(inp_str):
|
11 |
-
max_chunk = 500
|
12 |
-
inp_str = inp_str.replace('.', '.<eos>')
|
13 |
-
inp_str = inp_str.replace('?', '?<eos>')
|
14 |
-
inp_str = inp_str.replace('!', '!<eos>')
|
15 |
-
|
16 |
-
sentences = inp_str.split('<eos>')
|
17 |
-
current_chunk = 0
|
18 |
-
chunks = []
|
19 |
-
for sentence in sentences:
|
20 |
-
if len(chunks) == current_chunk + 1:
|
21 |
-
if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk:
|
22 |
-
chunks[current_chunk].extend(sentence.split(' '))
|
23 |
-
else:
|
24 |
-
current_chunk += 1
|
25 |
-
chunks.append(sentence.split(' '))
|
26 |
-
else:
|
27 |
-
chunks.append(sentence.split(' '))
|
28 |
-
|
29 |
-
for chunk_id in range(len(chunks)):
|
30 |
-
chunks[chunk_id] = ' '.join(chunks[chunk_id])
|
31 |
-
return chunks
|
32 |
-
|
33 |
-
|
34 |
summarizer = load_summarizer()
|
35 |
st.title("Patent Text Summarizer")
|
36 |
sentence = st.text_area('Please paste your Patent Text :', height=30)
|
37 |
button = st.button("Summarize")
|
38 |
|
39 |
-
max = st.sidebar.slider('Select max', 50, 500, step=10, value=
|
40 |
-
min = st.sidebar.slider('Select min', 10,
|
41 |
-
do_sample = st.sidebar.checkbox("Do sample", value=False)
|
42 |
with st.spinner("Generating Patent Summary.."):
|
43 |
if button and sentence:
|
44 |
-
chunks = generate_chunks(sentence)
|
45 |
-
res = summarizer(
|
46 |
max_length=max,
|
47 |
min_length=min,
|
48 |
-
do_sample=do_sample
|
|
|
49 |
text = ' '.join([summ['summary_text'] for summ in res])
|
50 |
# st.write(result[0]['summary_text'])
|
51 |
st.write(text)
|
|
|
6 |
model = pipeline("summarization", model="google/bigbird-pegasus-large-bigpatent")
|
7 |
return model
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
summarizer = load_summarizer()
|
10 |
st.title("Patent Text Summarizer")
|
11 |
sentence = st.text_area('Please paste your Patent Text :', height=30)
|
12 |
button = st.button("Summarize")
|
13 |
|
14 |
+
max = st.sidebar.slider('Select max', 50, 500, step=10, value=120)
|
15 |
+
min = st.sidebar.slider('Select min', 10, 50, step=10, value=50)
|
16 |
+
#do_sample = st.sidebar.checkbox("Do sample", value=False)
|
17 |
with st.spinner("Generating Patent Summary.."):
|
18 |
if button and sentence:
|
19 |
+
#chunks = generate_chunks(sentence)
|
20 |
+
res = summarizer(sentence,
|
21 |
max_length=max,
|
22 |
min_length=min,
|
23 |
+
#do_sample=do_sample
|
24 |
+
)
|
25 |
text = ' '.join([summ['summary_text'] for summ in res])
|
26 |
# st.write(result[0]['summary_text'])
|
27 |
st.write(text)
|