Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,20 +6,27 @@ import gradio as gr
|
|
| 6 |
with open("information.txt", "r", encoding="utf-8") as file:
|
| 7 |
info_text = file.read()
|
| 8 |
|
|
|
|
|
|
|
| 9 |
# function that cleans the chunks yoo
|
| 10 |
def preprocess_text(text):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
for chunk in chunks:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
return cleaned_chunks
|
| 21 |
cleaned_chunks = preprocess_text(info_text)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
print("Chunks:", cleaned_chunks)
|
| 24 |
print("Number of chunks:", len(cleaned_chunks))
|
| 25 |
|
|
|
|
| 6 |
with open("information.txt", "r", encoding="utf-8") as file:
|
| 7 |
info_text = file.read()
|
| 8 |
|
| 9 |
+
print("Raw text preview:", info_text[:200])
|
| 10 |
+
|
| 11 |
# function that cleans the chunks yoo
|
| 12 |
def preprocess_text(text):
|
| 13 |
+
chunks = text.split("\n") # simple + reliable
|
| 14 |
+
cleaned_chunks = [chunk.strip() for chunk in chunks if chunk.strip()]
|
| 15 |
+
# cleaned_text = text.strip()
|
| 16 |
+
# chunks = cleaned_text.split("\n")
|
| 17 |
+
# cleaned_chunks = []
|
| 18 |
|
| 19 |
+
# for chunk in chunks:
|
| 20 |
+
# chunk = chunk.strip()
|
| 21 |
+
# if chunk != "":
|
| 22 |
+
# cleaned_chunks:append(chunk)
|
| 23 |
|
| 24 |
return cleaned_chunks
|
| 25 |
cleaned_chunks = preprocess_text(info_text)
|
| 26 |
|
| 27 |
+
if len(cleaned_chunks) == 0:
|
| 28 |
+
raise ValueError("No valid text chunks found in information.txt")
|
| 29 |
+
|
| 30 |
print("Chunks:", cleaned_chunks)
|
| 31 |
print("Number of chunks:", len(cleaned_chunks))
|
| 32 |
|