Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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=
|
51 |
-
lines = text.
|
52 |
chunks = []
|
53 |
-
|
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(
|
57 |
-
|
58 |
else:
|
59 |
# If adding the line exceeds chunk size, store the current chunk and start a new one
|
60 |
-
chunks.append(
|
61 |
-
|
62 |
# Don't forget the last chunk
|
63 |
-
chunks.append(
|
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
|
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,"")
|