futranbg commited on
Commit
4517722
·
1 Parent(s): 7c99e18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -47,20 +47,20 @@ llm1 = HuggingFaceHub(repo_id=llama_repo, task="text-generation", model_kwargs=m
47
  llm2 = HuggingFaceHub(repo_id=starchat_repo, task="text-generation", model_kwargs=model_kwargs)
48
  llm3 = HuggingFaceHub(repo_id=bloom_repo, task="text-generation", model_kwargs=bloom_model_kwargs)
49
 
50
- def split_text_into_chunks(text, chunk_size=800):
51
- lines = text.splitlines()
52
  chunks = []
53
- temp_chunk = ""
54
  for line in lines:
55
  # If adding the current line doesn't exceed the chunk size, add the line to the chunk
56
- if len(temp_chunk) + len(line) <= chunk_size:
57
- temp_chunk += line + '\n'
58
  else:
59
  # If adding the line exceeds chunk size, store the current chunk and start a new one
60
- chunks.append(temp_chunk)
61
- temp_chunk = line + '\n'
62
  # Don't forget the last chunk
63
- chunks.append(temp_chunk)
64
  return chunks
65
 
66
  def translation(source, target, text):
@@ -70,7 +70,7 @@ def translation(source, target, text):
70
  try:
71
  input_prompt = bloom_template.replace("{source}", source)
72
  input_prompt = input_prompt.replace("{target}", target)
73
- input_prompt = input_prompt.replace("{query}", chunk.strip())
74
  stchunk = llm3(input_prompt)
75
  for eot in bloom_model_kwargs['stop']:
76
  stchunk = stchunk.replace(eot,"")
 
47
  llm2 = HuggingFaceHub(repo_id=starchat_repo, task="text-generation", model_kwargs=model_kwargs)
48
  llm3 = HuggingFaceHub(repo_id=bloom_repo, task="text-generation", model_kwargs=bloom_model_kwargs)
49
 
50
+ def split_text_into_chunks(text, chunk_size=1000):
51
+ lines = text.split('\n')
52
  chunks = []
53
+ chunk = ""
54
  for line in lines:
55
  # If adding the current line doesn't exceed the chunk size, add the line to the chunk
56
+ if len(chunk) + len(line) <= chunk_size:
57
+ chunk += line + '\n'
58
  else:
59
  # If adding the line exceeds chunk size, store the current chunk and start a new one
60
+ chunks.append(chunk)
61
+ chunk = line + '\n'
62
  # Don't forget the last chunk
63
+ chunks.append(chunk)
64
  return chunks
65
 
66
  def translation(source, target, text):
 
70
  try:
71
  input_prompt = bloom_template.replace("{source}", source)
72
  input_prompt = input_prompt.replace("{target}", target)
73
+ input_prompt = input_prompt.replace("{query}", chunk)
74
  stchunk = llm3(input_prompt)
75
  for eot in bloom_model_kwargs['stop']:
76
  stchunk = stchunk.replace(eot,"")