Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
# Load the summarization model pipeline
|
5 |
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
6 |
|
7 |
-
#
|
8 |
def summarize_text(text):
|
9 |
-
# Calculate dynamic chunk size (for example, we assume a max chunk of 1024 characters)
|
10 |
max_chunk_size = 1024 # Can be adjusted based on model's token limit (often 1024-2048 tokens)
|
11 |
|
12 |
# Split the text into chunks if it's longer than the max chunk size
|
@@ -18,9 +18,11 @@ def summarize_text(text):
|
|
18 |
else:
|
19 |
# If the text is small enough, use it as one chunk
|
20 |
text_chunks = [text]
|
21 |
-
|
22 |
-
#
|
23 |
-
|
|
|
|
|
24 |
|
25 |
# Combine all summaries into one
|
26 |
full_summary = " ".join(summaries)
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import concurrent.futures
|
4 |
|
5 |
# Load the summarization model pipeline
|
6 |
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
7 |
|
8 |
+
# Function to handle dynamic chunking of text and summarization in parallel
|
9 |
def summarize_text(text):
|
|
|
10 |
max_chunk_size = 1024 # Can be adjusted based on model's token limit (often 1024-2048 tokens)
|
11 |
|
12 |
# Split the text into chunks if it's longer than the max chunk size
|
|
|
18 |
else:
|
19 |
# If the text is small enough, use it as one chunk
|
20 |
text_chunks = [text]
|
21 |
+
|
22 |
+
# Use ThreadPoolExecutor to summarize each chunk in parallel
|
23 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
24 |
+
# Map summarizer function to each chunk in parallel
|
25 |
+
summaries = list(executor.map(lambda chunk: summarizer(chunk)[0]['summary_text'], text_chunks))
|
26 |
|
27 |
# Combine all summaries into one
|
28 |
full_summary = " ".join(summaries)
|