{ "cells": [ { "cell_type": "code", "execution_count": 4, "id": "83272ed4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2222136" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from glob import glob\n", "import os\n", "\n", "repository = 'mesolitica/pseudolabel-malaysian-youtube-whisper-large-v3-timestamp'\n", "folder = 'output-audio'\n", "files = glob(f'{folder}/*.mp3')\n", "len(files)" ] }, { "cell_type": "code", "execution_count": 2, "id": "3d83ced9", "metadata": {}, "outputs": [], "source": [ "import zipfile\n", "import mp\n", "import time\n", "from huggingface_hub import HfFileSystem\n", "from huggingface_hub import HfApi\n", "from tqdm import tqdm\n", "api = HfApi()\n", "\n", "partition_size = 5e+9" ] }, { "cell_type": "code", "execution_count": 5, "id": "de709a3a", "metadata": {}, "outputs": [], "source": [ "def loop(files):\n", " files, index = files\n", " current_index = 0\n", " api = HfApi()\n", " fs = HfFileSystem()\n", " total = 0\n", " temp = []\n", " for i in tqdm(range(len(files))):\n", " s = os.stat(files[i]).st_size\n", " if s + total >= partition_size:\n", " part_name = f\"{folder}-{index}-{current_index}.zip\"\n", " \n", " with zipfile.ZipFile(part_name, 'w', zipfile.ZIP_DEFLATED) as zipf:\n", " for f in temp:\n", " zipf.write(f, arcname=f)\n", "\n", " while True:\n", " try:\n", " api.upload_file(\n", " path_or_fileobj=part_name,\n", " path_in_repo=part_name,\n", " repo_id=repository,\n", " repo_type=\"dataset\",\n", " )\n", " break\n", " except:\n", " time.sleep(60)\n", "\n", " os.remove(part_name)\n", " \n", " current_index += 1\n", " temp = [files[i]]\n", " total = s\n", " else:\n", " temp.append(files[i])\n", " total += s\n", " \n", " if len(temp):\n", " part_name = f\"{folder}-{index}-{current_index}.zip\"\n", "\n", " with zipfile.ZipFile(part_name, 'w', zipfile.ZIP_DEFLATED) as zipf:\n", " for f in temp:\n", " zipf.write(f, arcname=f)\n", "\n", " while True:\n", " try:\n", " api.upload_file(\n", " path_or_fileobj=part_name,\n", " path_in_repo=part_name,\n", " repo_id=repository,\n", " repo_type=\"dataset\",\n", " )\n", " break\n", " except:\n", " time.sleep(60)\n", "\n", " os.remove(part_name)" ] }, { "cell_type": "code", "execution_count": 6, "id": "d4efaf5d", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|███████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:00<00:00, 172371.02it/s]\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "97f9290861bf4ac1ad1be838378eb598", "version_major": 2, "version_minor": 0 }, "text/plain": [ "output-audio-0-0.zip: 0%| | 0.00/153M [00:00