Spaces:
Build error
Build error
Create utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import zipfile
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def extract_zip(zip_file, extract_to):
|
| 5 |
+
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
|
| 6 |
+
zip_ref.extractall(extract_to)
|
| 7 |
+
|
| 8 |
+
def read_texts_from_folder(folder_path):
|
| 9 |
+
texts = []
|
| 10 |
+
for root, _, files in os.walk(folder_path):
|
| 11 |
+
for file in files:
|
| 12 |
+
if file.endswith(".txt"):
|
| 13 |
+
with open(os.path.join(root, file), 'r', encoding='utf-8') as f:
|
| 14 |
+
texts.append(f.read())
|
| 15 |
+
return texts
|