Spaces:
Runtime error
Runtime error
Create modules/data_loader.py
Browse files- modules/data_loader.py +17 -0
modules/data_loader.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# modules/data_loader.py
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from config.settings import DATA_PATH
|
| 5 |
+
|
| 6 |
+
def load_texts(file_path: str = DATA_PATH) -> list:
|
| 7 |
+
"""
|
| 8 |
+
Load text data from a .txt file.
|
| 9 |
+
Each line in the file is treated as a separate text entry.
|
| 10 |
+
"""
|
| 11 |
+
if not os.path.exists(file_path):
|
| 12 |
+
raise FileNotFoundError(f"Data file not found: {file_path}")
|
| 13 |
+
|
| 14 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 15 |
+
texts = [line.strip() for line in f.readlines() if line.strip()]
|
| 16 |
+
|
| 17 |
+
return texts
|