aquibmoin commited on
Commit
65d4a2a
1 Parent(s): 5112962

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
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
- sentences = re.split(r'(?<=[.!?]) +', text) # Split text into sentences
41
  chunks = []
42
  current_chunk = []
43
  current_length = 0
44
 
45
- for sentence in sentences:
46
- sentence_length = len(sentence.split())
47
- if current_length + sentence_length > chunk_size:
48
  chunks.append(" ".join(current_chunk))
49
- current_chunk = [sentence]
50
- current_length = sentence_length
51
  else:
52
- current_chunk.append(sentence)
53
- current_length += sentence_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))