Skip to content

Commit 928010d

Browse files
committed
Update test_sum.py
1 parent fa88b49 commit 928010d

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

Backend/test_sum.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,25 @@
77

88

99
def summary(text):
10-
1110
# Load the summarization pipeline
1211
summarizer = pipeline("summarization")
13-
1412
# Split the text into smaller chunks
1513
max_tokens_per_chunk = 1024 # Initial value
1614
max_words_in_summary = 2000000
17-
1815
# Calculate the maximum number of chunks needed
1916
max_num_chunks = (max_words_in_summary // max_tokens_per_chunk) + 1
20-
2117
# Split the text into chunks
2218
chunks = [text[i:i + max_tokens_per_chunk] for i in range(0, len(text), max_tokens_per_chunk)]
2319
# for the exceptions
2420
exceptions = "NULL"
25-
2621
# Generate summaries for each chunk
2722
summaries = []
2823
len_chunk=len(chunks)
2924
print("Note have been divided into chunks:"+str(len_chunk))
3025
for i, chunk in enumerate(chunks):
3126
# Reduce the chunk size dynamically if it exceeds the maximum sequence length
3227
while len(chunk) > max_tokens_per_chunk:
33-
max_tokens_per_chunk -= 50
34-
28+
max_tokens_per_chunk -= 50
3529
try:
3630
summary = summarizer(chunk, max_length=200, min_length=100, do_sample=False)
3731
summaries.append(summary[0]['summary_text']+"\n\n")
@@ -41,10 +35,8 @@ def summary(text):
4135
except Exception as e:
4236
print(f"An error occurred while summarizing chunk {i}: {str(e)}")
4337
exceptions = "\n".join(f"An error occurred while summarizing chunk {i}: {str(e)}")
44-
4538
# Combine the summaries into a single summary
4639
combined_summary = " ".join(summaries)
47-
4840
# Print and return the combined summary
4941
print("Combined Summary:")
5042
print(combined_summary)
@@ -55,7 +47,6 @@ def summary(text):
5547

5648

5749
async def gen_summary(file):
58-
5950
try:
6051
with open("dat.txt", "wb") as buffer: # saving file
6152
shutil.copyfileobj(file.file, buffer)
@@ -75,7 +66,6 @@ async def gen_summary(file):
7566
@router_summariser.post("/get-summary")
7667
async def get_summary(file: UploadFile = File(...)):
7768
data = await gen_summary(file)
78-
7969
return data
8070

8171

0 commit comments

Comments
 (0)