Anne314159 commited on
Commit
d2dbba3
·
verified ·
1 Parent(s): b028844

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -60,10 +60,33 @@ def fetch_full_article(url):
60
  # Initialize the summarization pipeline with BART
61
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  def generate_social_media_post(article_text):
64
- # Summarize the article text
65
- summary = summarizer(article_text, max_length=1000, min_length=200, do_sample=False)[0]['summary_text']
66
- return summary
 
 
 
 
 
 
 
67
 
68
 
69
 
@@ -103,7 +126,7 @@ def page_article_to_social_post():
103
 
104
  # Store the full article text in session state for later use
105
  st.session_state.full_article_text = article_text
106
-
107
  if st.button('Generate Social Media Post') and 'full_article_text' in st.session_state:
108
  with st.spinner('Generating...'):
109
  # Generate a summary based on the full article text
@@ -111,7 +134,6 @@ def page_article_to_social_post():
111
  st.success('Generated Content:')
112
  st.write(post_content)
113
 
114
-
115
  def page_test():
116
  st.title('Test Page')
117
  st.write('This is a test page with a test name.')
 
60
  # Initialize the summarization pipeline with BART
61
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
62
 
63
+ def split_text_into_chunks(text, chunk_size, overlap_size):
64
+ chunks = []
65
+ index = 0
66
+ while index < len(text):
67
+ # End index for the current chunk
68
+ end_index = index + chunk_size
69
+ # Extend the end index to include the overlap, if possible
70
+ end_index_with_overlap = min(end_index + overlap_size, len(text))
71
+ # Extract the chunk with the overlap
72
+ chunk = text[index:end_index_with_overlap]
73
+ chunks.append(chunk)
74
+ # Move the index to the start of the next chunk, which is end_index
75
+ index = end_index
76
+ return chunks
77
+
78
+
79
  def generate_social_media_post(article_text):
80
+ chunk_size = 900 # This is close to the model's maximum length for BART
81
+ overlap_size = 50 # Overlap size to ensure continuity in the text
82
+ chunks = split_text_into_chunks(article_text, chunk_size, overlap_size)
83
+
84
+ summarized_text = ''
85
+ for chunk in chunks:
86
+ # Call the summarizer for each chunk
87
+ summary = summarizer(chunk, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
88
+ summarized_text += summary + ' '
89
+ return summarized_text.strip()
90
 
91
 
92
 
 
126
 
127
  # Store the full article text in session state for later use
128
  st.session_state.full_article_text = article_text
129
+
130
  if st.button('Generate Social Media Post') and 'full_article_text' in st.session_state:
131
  with st.spinner('Generating...'):
132
  # Generate a summary based on the full article text
 
134
  st.success('Generated Content:')
135
  st.write(post_content)
136
 
 
137
  def page_test():
138
  st.title('Test Page')
139
  st.write('This is a test page with a test name.')