blazingbunny commited on
Commit
eb51c13
·
1 Parent(s): 74acb04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -1,13 +1,23 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
3
 
4
  st.title('Hugging Face BERT Summarizer')
5
  uploaded_file = st.file_uploader("Choose a .txt file", type="txt")
6
 
7
  if uploaded_file is not None:
8
  user_input = uploaded_file.read().decode('utf-8')
 
9
  if st.button('Summarize'):
10
  summarizer = pipeline('summarization')
11
- summarized = summarizer(user_input, max_length=130, min_length=30, do_sample=False)
12
- summarized_text = summarized[0]['summary_text']
 
 
 
 
 
 
 
 
13
  st.text_area('Summarized Text', summarized_text, height=200)
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ import textwrap
4
 
5
  st.title('Hugging Face BERT Summarizer')
6
  uploaded_file = st.file_uploader("Choose a .txt file", type="txt")
7
 
8
  if uploaded_file is not None:
9
  user_input = uploaded_file.read().decode('utf-8')
10
+
11
  if st.button('Summarize'):
12
  summarizer = pipeline('summarization')
13
+ summarized_text = ""
14
+
15
+ # Split the text into chunks of approximately 500 words each
16
+ chunks = textwrap.wrap(user_input, 500)
17
+
18
+ # Summarize each chunk
19
+ for chunk in chunks:
20
+ summarized = summarizer(chunk, max_length=130, min_length=30, do_sample=False)
21
+ summarized_text += summarized[0]['summary_text'] + " "
22
+
23
  st.text_area('Summarized Text', summarized_text, height=200)