spuun commited on
Commit
13dc7b9
·
1 Parent(s): 38a3929

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -8,13 +8,17 @@ def split_paragraph(paragraph, max_chunk_size=1024):
8
  words = paragraph.split()
9
  chunks = []
10
  current_chunk = []
 
11
 
12
  for word in words:
13
- if len(current_chunk) + len(word) + 1 <= max_chunk_size:
 
14
  current_chunk.append(word)
 
15
  else:
16
  chunks.append(' '.join(current_chunk))
17
  current_chunk = [word]
 
18
 
19
  if current_chunk:
20
  chunks.append(' '.join(current_chunk))
@@ -23,7 +27,7 @@ def split_paragraph(paragraph, max_chunk_size=1024):
23
 
24
  def launch(input):
25
  if len(input) > 1024:
26
- return " ".join([res["generated_text"] for res in generator(split_paragraph(input, 1024))])
27
  return generator(input)[0]["generated_text"]
28
 
29
  iface = gr.Interface(launch, inputs="text", outputs="text")
 
8
  words = paragraph.split()
9
  chunks = []
10
  current_chunk = []
11
+ current_chunk_size = 0
12
 
13
  for word in words:
14
+ word_len = len(word) + 1 # Add 1 for the space
15
+ if current_chunk_size + word_len <= max_chunk_size:
16
  current_chunk.append(word)
17
+ current_chunk_size += word_len
18
  else:
19
  chunks.append(' '.join(current_chunk))
20
  current_chunk = [word]
21
+ current_chunk_size = word_len
22
 
23
  if current_chunk:
24
  chunks.append(' '.join(current_chunk))
 
27
 
28
  def launch(input):
29
  if len(input) > 1024:
30
+ return " ".join([res["generated_text"] for res in generator(split_paragraph(input))])
31
  return generator(input)[0]["generated_text"]
32
 
33
  iface = gr.Interface(launch, inputs="text", outputs="text")