Spaces:
Sleeping
Sleeping
update loading for new huggingface_hub
Browse files- mgr_biases.py +21 -0
mgr_biases.py
CHANGED
@@ -6,6 +6,7 @@ import re
|
|
6 |
import pandas as pd
|
7 |
import numpy as np
|
8 |
import glob
|
|
|
9 |
import huggingface_hub
|
10 |
print("hfh", huggingface_hub.__version__)
|
11 |
from huggingface_hub import hf_hub_download, upload_file, delete_file, snapshot_download, list_repo_files, dataset_info
|
@@ -181,6 +182,19 @@ def retrievePredefinedBiases():
|
|
181 |
|
182 |
return flt_files
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
# https://huggingface.co/spaces/elonmuskceo/persistent-data/blob/main/app.py
|
185 |
def get_bias_json(filepath: str):
|
186 |
filename = os.path.basename(filepath)
|
@@ -198,6 +212,13 @@ def get_bias_json(filepath: str):
|
|
198 |
# file not found
|
199 |
print(f"file not found, probably: {e}")
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
with open(os.path.join(LOCAL_DATA_DIRNAME, filename)) as f:
|
202 |
bias_json = json.load(f)
|
203 |
|
|
|
6 |
import pandas as pd
|
7 |
import numpy as np
|
8 |
import glob
|
9 |
+
from pathlib import Path
|
10 |
import huggingface_hub
|
11 |
print("hfh", huggingface_hub.__version__)
|
12 |
from huggingface_hub import hf_hub_download, upload_file, delete_file, snapshot_download, list_repo_files, dataset_info
|
|
|
182 |
|
183 |
return flt_files
|
184 |
|
185 |
+
def list_folders_sorted_by_date(path):
|
186 |
+
# Convert string path to a Path object
|
187 |
+
directory = Path(path)
|
188 |
+
|
189 |
+
# Get all folders in the given directory
|
190 |
+
folders = [f for f in directory.iterdir() if f.is_dir()]
|
191 |
+
|
192 |
+
# Sort folders by modification time, most recent first
|
193 |
+
sorted_folders = sorted(folders, key=lambda x: x.stat().st_mtime, reverse=True)
|
194 |
+
|
195 |
+
# Return folder names
|
196 |
+
return [folder.name for folder in sorted_folders]
|
197 |
+
|
198 |
# https://huggingface.co/spaces/elonmuskceo/persistent-data/blob/main/app.py
|
199 |
def get_bias_json(filepath: str):
|
200 |
filename = os.path.basename(filepath)
|
|
|
212 |
# file not found
|
213 |
print(f"file not found, probably: {e}")
|
214 |
|
215 |
+
ds_local_path = os.path.join(LOCAL_DATA_DIRNAME,
|
216 |
+
"datasets--AnimaLab--bias-test-gpt-biases",
|
217 |
+
"snapshots")
|
218 |
+
folders_sorted = list_folders_sorted_by_date(ds_local_path)
|
219 |
+
print("---FOLDERS---")
|
220 |
+
print(folders_sorted[0])
|
221 |
+
|
222 |
with open(os.path.join(LOCAL_DATA_DIRNAME, filename)) as f:
|
223 |
bias_json = json.load(f)
|
224 |
|