Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
# Load the text summarization pipeline
|
5 |
summarizer = pipeline("summarization", model="astro21/bart-cls")
|
6 |
|
|
|
|
|
7 |
def summarize_text(input_text):
|
8 |
-
# Use
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
demo = gr.Interface(fn=
|
13 |
|
14 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import os
|
4 |
|
5 |
# Load the text summarization pipeline
|
6 |
summarizer = pipeline("summarization", model="astro21/bart-cls")
|
7 |
|
8 |
+
chunk_counter = 0
|
9 |
+
|
10 |
def summarize_text(input_text):
|
11 |
+
global chunk_counter # Use a global variable to keep track of the chunk number
|
12 |
+
chunk_counter = 0 # Initialize the chunk counter
|
13 |
+
|
14 |
+
# Split the input text into chunks with a maximum size of 512
|
15 |
+
max_chunk_size = 512
|
16 |
+
chunks = [input_text[i:i+max_chunk_size] for i in range(0, len(input_text), max_chunk_size)]
|
17 |
+
|
18 |
+
summarized_chunks = []
|
19 |
+
for chunk in chunks:
|
20 |
+
chunk_counter += 1
|
21 |
+
print(f"Chunk {chunk_counter}:") # Print the chunk number
|
22 |
+
# Summarize each chunk
|
23 |
+
summarized_chunk = summarizer(chunk, max_length=128, min_length=64, do_sample=False)[0]['summary_text']
|
24 |
+
summarized_chunks.append(summarized_chunk)
|
25 |
+
|
26 |
+
# Concatenate the summaries
|
27 |
+
summarized_text = "\n".join(summarized_chunks)
|
28 |
+
return summarized_text
|
29 |
+
|
30 |
+
def summarize_text_file(file):
|
31 |
+
if file is not None:
|
32 |
+
content = file.read().decode("utf-8")
|
33 |
+
return summarize_text(content)
|
34 |
+
|
35 |
+
input_type = gr.inputs.File("text")
|
36 |
|
37 |
+
demo = gr.Interface(fn=summarize_text_file, inputs=input_type, outputs="text", live=True)
|
38 |
|
39 |
+
demo.launch()
|