|
|
import json |
|
|
import uuid |
|
|
import os |
|
|
from huggingface_hub import HfApi |
|
|
|
|
|
def add_ids_to_jsonl(file_path): |
|
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as f: |
|
|
lines = f.readlines() |
|
|
|
|
|
|
|
|
updated_lines = [] |
|
|
for line in lines: |
|
|
data = json.loads(line) |
|
|
|
|
|
unique_id = str(uuid.uuid4()) + str(uuid.uuid4())[:18] |
|
|
data['id'] = unique_id |
|
|
updated_lines.append(json.dumps(data, ensure_ascii=False) + '\n') |
|
|
|
|
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as f: |
|
|
f.writelines(updated_lines) |
|
|
|
|
|
def main(): |
|
|
|
|
|
directories = ['train', 'test', 'validation'] |
|
|
for directory in directories: |
|
|
metadata_path = os.path.join(directory, 'metadata.jsonl') |
|
|
if os.path.exists(metadata_path): |
|
|
print(f"Ajout d'IDs au fichier {metadata_path}") |
|
|
add_ids_to_jsonl(metadata_path) |
|
|
|
|
|
|
|
|
token = os.getenv('HF_TOKEN') |
|
|
if not token: |
|
|
print("Erreur : La variable d'environnement HF_TOKEN n'est pas définie") |
|
|
return |
|
|
|
|
|
api = HfApi() |
|
|
api.upload_folder( |
|
|
folder_path=".", |
|
|
repo_id="Marsouuu/french-kid", |
|
|
repo_type="dataset", |
|
|
token=token |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |