Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,18 @@ from langchain.text_splitter import (
|
|
4 |
RecursiveCharacterTextSplitter,
|
5 |
)
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def chunk(text, length, splitter_selection, separators_str):
|
9 |
-
|
10 |
-
separators = separators_str[1:-1].split(", ")
|
11 |
-
separators = [separator.replace('"', "").replace("'", "") for separator in separators]
|
12 |
|
13 |
if splitter_selection == "LangChain's CharacterTextSplitter":
|
14 |
text_splitter = CharacterTextSplitter(
|
|
|
4 |
RecursiveCharacterTextSplitter,
|
5 |
)
|
6 |
|
7 |
+
def extract_separators_from_string(separator_str):
|
8 |
+
try:
|
9 |
+
separators = separators_str[1:-1].split(", ")
|
10 |
+
return [separator.replace('"', "").replace("'", "") for separator in separators]
|
11 |
+
except:
|
12 |
+
raise gr.Error(f"""
|
13 |
+
Did not succeed in extracting seperators from string: {separator_str}.
|
14 |
+
Please type it in the correct format: "['separator_1', 'separator_2', etc]"
|
15 |
+
""")
|
16 |
+
|
17 |
def chunk(text, length, splitter_selection, separators_str):
|
18 |
+
separators = extract_separators_from_string(separators_str)
|
|
|
|
|
19 |
|
20 |
if splitter_selection == "LangChain's CharacterTextSplitter":
|
21 |
text_splitter = CharacterTextSplitter(
|