Spaces:
Sleeping
Sleeping
Delete test.py
Browse files
test.py
DELETED
@@ -1,46 +0,0 @@
|
|
1 |
-
from huggingface_hub import HfFileSystem
|
2 |
-
|
3 |
-
def manage_hf_files(hf_token):
|
4 |
-
# Initialize the Hugging Face file system
|
5 |
-
fs = HfFileSystem(token = hf_token)
|
6 |
-
|
7 |
-
try:
|
8 |
-
# List all files in a directory
|
9 |
-
print("Listing all files in the directory:")
|
10 |
-
files_in_dir = fs.ls("datasets/bupa1018/Test/data", detail=False)
|
11 |
-
for file in files_in_dir:
|
12 |
-
print(file)
|
13 |
-
|
14 |
-
# List all ".csv" files in a repository
|
15 |
-
print("\nListing all '.csv' files in the repository:")
|
16 |
-
csv_files = fs.glob("datasets/bupa1018/Test/**/*.csv")
|
17 |
-
for csv_file in csv_files:
|
18 |
-
print(csv_file)
|
19 |
-
|
20 |
-
print("\nListing all '.csv' files in the repository:")
|
21 |
-
json_files = fs.glob("datasets/bupa1018/Test/**/*.json")
|
22 |
-
for json_file in json_files:
|
23 |
-
print("Json_File:", json_file)
|
24 |
-
|
25 |
-
# Read a remote file line-by-line
|
26 |
-
print("\nReading the content of 'repo_data.json' (line-by-line):")
|
27 |
-
with fs.open("datasets/bupa1018/Test/data/repo_data.json", "r") as f:
|
28 |
-
repo_data = f.readlines()
|
29 |
-
for line in repo_data:
|
30 |
-
print(line.strip())
|
31 |
-
|
32 |
-
# Read the content of a remote file as a single string
|
33 |
-
print("\nReading the content of 'repo_data.json' (as a single string):")
|
34 |
-
train_data = fs.read_text("datasets/bupa1018/Test/data/repo_data.json")
|
35 |
-
print("print the content of a remote file as a single string")
|
36 |
-
print(train_data)
|
37 |
-
|
38 |
-
# Write to a remote filehd
|
39 |
-
print("\nWriting to 'hello.csv':")
|
40 |
-
with fs.open("datasets/bupa1018/Test/data/hello2.csv", "w") as f:
|
41 |
-
f.write("text,label\n")
|
42 |
-
f.write("Fantastic movie!,good\n")
|
43 |
-
print("Data successfully written to 'hello.csv'.")
|
44 |
-
|
45 |
-
except Exception as e:
|
46 |
-
print(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|