Spaces:
Sleeping
Sleeping
Update utilities/setup.py
Browse files- utilities/setup.py +35 -6
utilities/setup.py
CHANGED
@@ -1,10 +1,39 @@
|
|
1 |
import json
|
2 |
import os
|
|
|
3 |
|
|
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
import os
|
3 |
+
from datasets import load_dataset
|
4 |
|
5 |
+
class get_files:
|
6 |
|
7 |
+
def predefined_dataset(dataset_name):
|
8 |
+
global dataset # bad practice, I know... But just bear with me. Will later update to state dict.
|
9 |
+
dataset = load_dataset(dataset_name, split = "train")
|
10 |
+
return 'Successfully loaded dataset'
|
11 |
+
|
12 |
+
def uploaded_dataset(file):
|
13 |
+
global dataset # bad practice, I know... But just bear with me. Will later update to state dict.
|
14 |
+
dataset = []
|
15 |
+
if file is None:
|
16 |
+
return "File not found. Please upload the file again."
|
17 |
+
try:
|
18 |
+
with open(file,'r') as file:
|
19 |
+
for line in file:
|
20 |
+
dataset.append(json.loads(line.strip()))
|
21 |
+
return "File retrieved."
|
22 |
+
except FileNotFoundError:
|
23 |
+
return "File not found. Please upload the file again."
|
24 |
+
|
25 |
+
def load_markdown_file(file_path):
|
26 |
+
try:
|
27 |
+
with open(file_path, 'r') as f:
|
28 |
+
return f.read()
|
29 |
+
except FileNotFoundError:
|
30 |
+
return "File not found. Please check the file path."
|
31 |
+
except Exception as e:
|
32 |
+
return f"Error loading file: {str(e)}"
|
33 |
+
|
34 |
+
def json_cfg():
|
35 |
+
"""Retrieve configuration file"""
|
36 |
+
config_path = os.getenv('CONFIG_PATH')
|
37 |
+
with open(config_path, 'r') as file:
|
38 |
+
config = json.load(file)
|
39 |
+
return config
|