Update app.py
Browse files
app.py
CHANGED
@@ -37,20 +37,20 @@ def format_output(response, sentences):
|
|
37 |
return f"Unexpected response format: {response}"
|
38 |
|
39 |
def split_into_chunks(text, chunk_size=100):
|
40 |
-
|
41 |
chunks = []
|
42 |
current_chunk = []
|
43 |
current_length = 0
|
44 |
|
45 |
-
for
|
46 |
-
|
47 |
-
if current_length +
|
48 |
chunks.append(" ".join(current_chunk))
|
49 |
-
current_chunk = [
|
50 |
-
current_length =
|
51 |
else:
|
52 |
-
current_chunk.append(
|
53 |
-
current_length +=
|
54 |
|
55 |
if current_chunk:
|
56 |
chunks.append(" ".join(current_chunk))
|
|
|
37 |
return f"Unexpected response format: {response}"
|
38 |
|
39 |
def split_into_chunks(text, chunk_size=100):
|
40 |
+
paragraphs = text.split('\n\n') # Split text into paragraphs
|
41 |
chunks = []
|
42 |
current_chunk = []
|
43 |
current_length = 0
|
44 |
|
45 |
+
for paragraph in paragraphs:
|
46 |
+
paragraph_length = len(paragraph.split())
|
47 |
+
if current_length + paragraph_length > chunk_size:
|
48 |
chunks.append(" ".join(current_chunk))
|
49 |
+
current_chunk = [paragraph]
|
50 |
+
current_length = paragraph_length
|
51 |
else:
|
52 |
+
current_chunk.append(paragraph)
|
53 |
+
current_length += paragraph_length
|
54 |
|
55 |
if current_chunk:
|
56 |
chunks.append(" ".join(current_chunk))
|