Upload create_checksums.py
Browse files- create_checksums.py +53 -0
create_checksums.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import hashlib
|
3 |
+
import glob
|
4 |
+
import pathlib
|
5 |
+
from tqdm import tqdm
|
6 |
+
import subprocess
|
7 |
+
|
8 |
+
|
9 |
+
all_files = glob.glob("./*")
|
10 |
+
|
11 |
+
folder_path = pathlib.Path("train_valid_data")
|
12 |
+
print(folder_path)
|
13 |
+
|
14 |
+
all_files = list(folder_path.rglob("*"))
|
15 |
+
|
16 |
+
all_files = [i for i in all_files if not os.path.isdir(i)]
|
17 |
+
from pprint import pprint
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
def get_checksum(file_path):
|
22 |
+
|
23 |
+
output = str(subprocess.Popen(["/usr/bin/sha256sum" , str(file_path)], stdout=subprocess.PIPE).communicate()[0].decode("UTF-8"))
|
24 |
+
|
25 |
+
output = output.replace(" ", ",")
|
26 |
+
return output
|
27 |
+
|
28 |
+
# print(get_checksum(all_files[0]))
|
29 |
+
|
30 |
+
# all_files = all_files[:5]
|
31 |
+
|
32 |
+
with open("sha256_checksums.csv", "w+") as file:
|
33 |
+
file.write("checksum,file_path\n")
|
34 |
+
for file_path in tqdm(all_files):
|
35 |
+
file.write(get_checksum(file_path))
|
36 |
+
|
37 |
+
|
38 |
+
import huggingface as hh
|
39 |
+
|
40 |
+
|
41 |
+
from huggingface_hub import HfApi
|
42 |
+
|
43 |
+
api = HfApi()
|
44 |
+
# upload results to a public dataset
|
45 |
+
# also save as a file
|
46 |
+
api.upload_file(
|
47 |
+
path_or_fileobj="sha256_checksums.csv",
|
48 |
+
path_in_repo="sha256_checksums.csv",
|
49 |
+
repo_id="osbm/project-checksums",
|
50 |
+
repo_type="dataset",
|
51 |
+
token="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"
|
52 |
+
|
53 |
+
)
|