{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Fetch the npz from s3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T00:36:56.065152Z",
     "start_time": "2024-05-26T00:36:54.886147Z"
    },
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:40.034378Z",
     "iopub.status.busy": "2025-10-26T01:29:40.034125Z",
     "iopub.status.idle": "2025-10-26T01:29:41.213427Z",
     "shell.execute_reply": "2025-10-26T01:29:41.212884Z",
     "shell.execute_reply.started": "2025-10-26T01:29:40.034361Z"
    }
   },
   "outputs": [],
   "source": [
    "import ast\n",
    "import os\n",
    "import sys\n",
    "from collections import defaultdict\n",
    "import datetime\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "from suno_utils.utils.s3 import download_s3_files\n",
    "from suno_utils.utils.text import read_json, read_jsonl, write_json, write_jsonl\n",
    "from tqdm import tqdm\n",
    "\n",
    "sys.path.insert(0, \"/home/tony/Work/neon/sunoGPT/scripts/\")\n",
    "\n",
    "import numpy as np\n",
    "from data_preparation_7b import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T00:36:56.068073Z",
     "start_time": "2024-05-26T00:36:56.066469Z"
    },
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:41.215432Z",
     "iopub.status.busy": "2025-10-26T01:29:41.215306Z",
     "iopub.status.idle": "2025-10-26T01:29:41.217643Z",
     "shell.execute_reply": "2025-10-26T01:29:41.217238Z",
     "shell.execute_reply.started": "2025-10-26T01:29:41.215417Z"
    }
   },
   "outputs": [],
   "source": [
    "NPZ_DIR = \"/app2/suno/data/dpo/dorado_t1\"\n",
    "JSON_DIR = \"/app2/suno/data/dpo/dorado_t1_json/\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:41.219359Z",
     "iopub.status.busy": "2025-10-26T01:29:41.219230Z",
     "iopub.status.idle": "2025-10-26T01:29:41.222028Z",
     "shell.execute_reply": "2025-10-26T01:29:41.221611Z",
     "shell.execute_reply.started": "2025-10-26T01:29:41.219345Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Today's date: 20251026 Full datetime: 2025-10-26 01:29:41.220189\n"
     ]
    }
   ],
   "source": [
    "# Get today's date\n",
    "# Format it the same way as your variable\n",
    "today = datetime.datetime.now()\n",
    "todays_save_date = today.strftime(\"%Y%m%d\")\n",
    "print(f\"Today's date: {todays_save_date}\", f\"Full datetime: {today}\")\n",
    "# todays_save_date = \"20251014\"\n",
    "\n",
    "data_file = f\"interesting_clips_dorado_t1_{todays_save_date}.pkl\"\n",
    "data_csv_path = f\"/home/tony/Data/Preference/dorado_t1/{data_file}\"\n",
    "# data_csv_path = \"/home/tony/Data/Preference/up_v2_d4/fully_merged_up_v2_d4.pkl\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T00:36:59.932066Z",
     "start_time": "2024-05-26T00:36:56.069087Z"
    },
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:41.223629Z",
     "iopub.status.busy": "2025-10-26T01:29:41.223513Z",
     "iopub.status.idle": "2025-10-26T01:29:42.656625Z",
     "shell.execute_reply": "2025-10-26T01:29:42.656095Z",
     "shell.execute_reply.started": "2025-10-26T01:29:41.223616Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(101478, 91)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df = pd.read_csv(data_csv_path)\n",
    "df = pd.read_pickle(data_csv_path)\n",
    "df.shape\n",
    "# v2: (2341508, 31)\n",
    "# v3: (2609830, 31)\n",
    "# v4: (1926120, 35)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:42.658575Z",
     "iopub.status.busy": "2025-10-26T01:29:42.658449Z",
     "iopub.status.idle": "2025-10-26T01:29:42.734103Z",
     "shell.execute_reply": "2025-10-26T01:29:42.733562Z",
     "shell.execute_reply.started": "2025-10-26T01:29:42.658560Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(101478, 91)\n",
      "model_name\n",
      "chirp-carp-up-c-1    101478\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "df = df[df[\"model_name\"].str.contains(\"up\")]\n",
    "print(df.shape)\n",
    "# for extend, also fetch their parents\n",
    "print(df[\"model_name\"].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:42.736303Z",
     "iopub.status.busy": "2025-10-26T01:29:42.735531Z",
     "iopub.status.idle": "2025-10-26T01:29:42.739518Z",
     "shell.execute_reply": "2025-10-26T01:29:42.738927Z",
     "shell.execute_reply.started": "2025-10-26T01:29:42.736281Z"
    }
   },
   "outputs": [],
   "source": [
    "# if \"extend\" in data_csv_path:\n",
    "# test_slice = df[\"metadata\"].apply(lambda x: ast.literal_eval(x))\n",
    "# test_slice_series = test_slice.apply(pd.Series)\n",
    "# df = pd.concat([df, test_slice_series], axis=1, join=\"inner\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:42.740412Z",
     "iopub.status.busy": "2025-10-26T01:29:42.740047Z",
     "iopub.status.idle": "2025-10-26T01:29:42.834078Z",
     "shell.execute_reply": "2025-10-26T01:29:42.833584Z",
     "shell.execute_reply.started": "2025-10-26T01:29:42.740397Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "all 101006\n",
      "unique 50240\n"
     ]
    }
   ],
   "source": [
    "edit_clip_ids = df[\"metadata\"].apply(lambda x: x.get(\"upsample_clip_id\", \"\"))\n",
    "s3_ids = [s3_id for s3_id in edit_clip_ids if s3_id and len(s3_id) > 0]\n",
    "print(\"all\", len(s3_ids))\n",
    "unique_s3_ids = sorted(set(s3_ids))\n",
    "print(\"unique\", len(unique_s3_ids))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T00:36:59.940064Z",
     "start_time": "2024-05-26T00:36:59.933947Z"
    },
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:42.834866Z",
     "iopub.status.busy": "2025-10-26T01:29:42.834718Z",
     "iopub.status.idle": "2025-10-26T01:29:42.853694Z",
     "shell.execute_reply": "2025-10-26T01:29:42.853348Z",
     "shell.execute_reply.started": "2025-10-26T01:29:42.834851Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "50240\n",
      "full 50240\n"
     ]
    }
   ],
   "source": [
    "# download all clips; 883k\n",
    "from suno_utils.utils.s3 import download_s3_files\n",
    "\n",
    "s3_ids = unique_s3_ids.copy()\n",
    "print(len(s3_ids))\n",
    "# s3_ids = set(s3_ids).union(set(df[\"audio_prompt_id\"].values))\n",
    "print(\"full\", len(s3_ids))\n",
    "s3_paths = [f\"s3://suno-data-uploads/studio/uploads/{s3_id}.npz\" for s3_id in s3_ids]\n",
    "local_paths = [f\"{NPZ_DIR}/{s3_id}.npz\" for s3_id in s3_ids]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T00:37:00.153602Z",
     "start_time": "2024-05-26T00:36:59.941125Z"
    },
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:42.854461Z",
     "iopub.status.busy": "2025-10-26T01:29:42.854209Z",
     "iopub.status.idle": "2025-10-26T01:29:47.007902Z",
     "shell.execute_reply": "2025-10-26T01:29:47.007197Z",
     "shell.execute_reply.started": "2025-10-26T01:29:42.854446Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jobs to be done 2072 2072\n"
     ]
    }
   ],
   "source": [
    "finished_paths = os.listdir(NPZ_DIR)\n",
    "finished_paths_set = set(finished_paths)\n",
    "unfinished_s3_paths = [\n",
    "    path for path in s3_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "unfinished_paths = [\n",
    "    path for path in local_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "unfinished_ids_set = set([os.path.basename(path).replace(\".npz\", \"\") for path in unfinished_paths])\n",
    "unfinished_ids = [i for i in s3_ids if i in unfinished_ids_set]\n",
    "print(\"jobs to be done\", len(unfinished_paths), len(unfinished_s3_paths))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T00:49:33.275556Z",
     "start_time": "2024-05-26T00:37:00.154648Z"
    },
    "execution": {
     "iopub.execute_input": "2025-10-26T01:29:47.008744Z",
     "iopub.status.busy": "2025-10-26T01:29:47.008578Z",
     "iopub.status.idle": "2025-10-26T01:31:23.243447Z",
     "shell.execute_reply": "2025-10-26T01:31:23.242609Z",
     "shell.execute_reply.started": "2025-10-26T01:29:47.008729Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [01:36<00:00, 32.07s/it]\n"
     ]
    }
   ],
   "source": [
    "_ = download_s3_files(unfinished_s3_paths, unfinished_paths, n_cores=32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T00:59:42.420025Z",
     "start_time": "2024-05-26T00:49:33.276845Z"
    },
    "execution": {
     "iopub.execute_input": "2025-10-26T01:31:23.244633Z",
     "iopub.status.busy": "2025-10-26T01:31:23.244329Z",
     "iopub.status.idle": "2025-10-26T01:31:27.520247Z",
     "shell.execute_reply": "2025-10-26T01:31:27.519594Z",
     "shell.execute_reply.started": "2025-10-26T01:31:23.244615Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jobs to be done 19 19\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  1.26it/s]\n"
     ]
    }
   ],
   "source": [
    "# # deleted files are at: deleted; try to get them as well\n",
    "finished_paths = os.listdir(NPZ_DIR)\n",
    "finished_paths_set = set(finished_paths)\n",
    "unfinished_s3_paths = [\n",
    "    path for path in s3_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "unfinished_paths = [\n",
    "    path for path in local_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "print(\"jobs to be done\", len(unfinished_paths), len(unfinished_s3_paths))\n",
    "unfinished_deleted_s3_paths = [\n",
    "    path.replace(\"/uploads/\", \"/deleted/\") for path in unfinished_s3_paths\n",
    "]\n",
    "_ = download_s3_files(unfinished_deleted_s3_paths, unfinished_paths, n_cores=32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T00:59:42.423220Z",
     "start_time": "2024-05-26T00:59:42.421231Z"
    },
    "execution": {
     "iopub.execute_input": "2025-10-26T01:31:27.521238Z",
     "iopub.status.busy": "2025-10-26T01:31:27.520994Z",
     "iopub.status.idle": "2025-10-26T01:31:27.524099Z",
     "shell.execute_reply": "2025-10-26T01:31:27.523557Z",
     "shell.execute_reply.started": "2025-10-26T01:31:27.521222Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finish downloads\n"
     ]
    }
   ],
   "source": [
    "print(\"Finish downloads\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# VAE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:31:27.525061Z",
     "iopub.status.busy": "2025-10-26T01:31:27.524688Z",
     "iopub.status.idle": "2025-10-26T01:31:27.569130Z",
     "shell.execute_reply": "2025-10-26T01:31:27.568576Z",
     "shell.execute_reply.started": "2025-10-26T01:31:27.525044Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "101478\n",
      "full 101478\n"
     ]
    }
   ],
   "source": [
    "# download all clips; 883k\n",
    "from suno_utils.utils.s3 import download_s3_files\n",
    "\n",
    "# for vae...we actually need the original s3 id\n",
    "s3_ids = df[\"s3_id\"].unique()\n",
    "print(len(s3_ids))\n",
    "# s3_ids = set(s3_ids).union(set(df[\"audio_prompt_id\"].values))\n",
    "print(\"full\", len(s3_ids))\n",
    "s3_paths = [f\"s3://suno-data-uploads/studio/uploads/{s3_id}_vae.npz\" for s3_id in s3_ids]\n",
    "local_paths = [f\"{NPZ_DIR}/{s3_id}_vae.npz\" for s3_id in s3_ids]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:31:27.570088Z",
     "iopub.status.busy": "2025-10-26T01:31:27.569710Z",
     "iopub.status.idle": "2025-10-26T01:31:31.135047Z",
     "shell.execute_reply": "2025-10-26T01:31:31.134349Z",
     "shell.execute_reply.started": "2025-10-26T01:31:27.570072Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jobs to be done 6658 6658\n"
     ]
    }
   ],
   "source": [
    "finished_paths = os.listdir(NPZ_DIR)\n",
    "finished_paths_set = set(finished_paths)\n",
    "unfinished_s3_paths = [\n",
    "    path for path in s3_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "unfinished_paths = [\n",
    "    path for path in local_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "unfinished_ids_set = set([os.path.basename(path).replace(\".npz\", \"\") for path in unfinished_paths])\n",
    "unfinished_ids = [i for i in s3_ids if i in unfinished_ids_set]\n",
    "print(\"jobs to be done\", len(unfinished_paths), len(unfinished_s3_paths))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:31:31.136015Z",
     "iopub.status.busy": "2025-10-26T01:31:31.135755Z",
     "iopub.status.idle": "2025-10-26T01:36:28.076133Z",
     "shell.execute_reply": "2025-10-26T01:36:28.075578Z",
     "shell.execute_reply.started": "2025-10-26T01:31:31.135999Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [04:56<00:00, 42.41s/it]\n"
     ]
    }
   ],
   "source": [
    "_ = download_s3_files(unfinished_s3_paths, unfinished_paths, n_cores=32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:36:28.077073Z",
     "iopub.status.busy": "2025-10-26T01:36:28.076869Z",
     "iopub.status.idle": "2025-10-26T01:36:32.349736Z",
     "shell.execute_reply": "2025-10-26T01:36:32.349178Z",
     "shell.execute_reply.started": "2025-10-26T01:36:28.077055Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jobs to be done 0 0\n"
     ]
    }
   ],
   "source": [
    "# # deleted files are at: deleted; try to get them as well\n",
    "finished_paths = os.listdir(NPZ_DIR)\n",
    "finished_paths_set = set(finished_paths)\n",
    "unfinished_s3_paths = [\n",
    "    path for path in s3_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "unfinished_paths = [\n",
    "    path for path in local_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "print(\"jobs to be done\", len(unfinished_paths), len(unfinished_s3_paths))\n",
    "unfinished_deleted_s3_paths = [\n",
    "    path.replace(\"/uploads/\", \"/deleted/\") for path in unfinished_s3_paths\n",
    "]\n",
    "_ = download_s3_files(unfinished_deleted_s3_paths, unfinished_paths, n_cores=32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:36:32.350501Z",
     "iopub.status.busy": "2025-10-26T01:36:32.350344Z",
     "iopub.status.idle": "2025-10-26T01:36:32.353096Z",
     "shell.execute_reply": "2025-10-26T01:36:32.352704Z",
     "shell.execute_reply.started": "2025-10-26T01:36:32.350485Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DONE with vaes\n"
     ]
    }
   ],
   "source": [
    "print(\"DONE with vaes\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:36:32.353706Z",
     "iopub.status.busy": "2025-10-26T01:36:32.353579Z",
     "iopub.status.idle": "2025-10-26T01:36:32.355562Z",
     "shell.execute_reply": "2025-10-26T01:36:32.355187Z",
     "shell.execute_reply.started": "2025-10-26T01:36:32.353694Z"
    }
   },
   "outputs": [],
   "source": [
    "# BREAK"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Hoot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:36:32.356143Z",
     "iopub.status.busy": "2025-10-26T01:36:32.356014Z",
     "iopub.status.idle": "2025-10-26T01:36:32.391311Z",
     "shell.execute_reply": "2025-10-26T01:36:32.390850Z",
     "shell.execute_reply.started": "2025-10-26T01:36:32.356130Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "101478\n"
     ]
    }
   ],
   "source": [
    "s3_ids = df[\"s3_id\"].unique()\n",
    "print(len(s3_ids))\n",
    "s3_paths = [f\"s3://suno-data-uploads/studio/uploads/{s3_id}_hoot.json\" for s3_id in s3_ids]\n",
    "local_paths = [f\"{JSON_DIR}/{s3_id}_hoot.json\" for s3_id in s3_ids]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:36:32.393995Z",
     "iopub.status.busy": "2025-10-26T01:36:32.393754Z",
     "iopub.status.idle": "2025-10-26T01:36:32.522909Z",
     "shell.execute_reply": "2025-10-26T01:36:32.522436Z",
     "shell.execute_reply.started": "2025-10-26T01:36:32.393979Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jobs to be done 6674 6674\n"
     ]
    }
   ],
   "source": [
    "finished_paths = os.listdir(JSON_DIR)\n",
    "finished_paths_set = set(finished_paths)\n",
    "unfinished_s3_paths = [\n",
    "    path for path in s3_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "unfinished_paths = [\n",
    "    path for path in local_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "print(\"jobs to be done\", len(unfinished_paths), len(unfinished_s3_paths))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:36:32.523558Z",
     "iopub.status.busy": "2025-10-26T01:36:32.523415Z",
     "iopub.status.idle": "2025-10-26T01:41:19.220472Z",
     "shell.execute_reply": "2025-10-26T01:41:19.219910Z",
     "shell.execute_reply.started": "2025-10-26T01:36:32.523544Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [04:46<00:00, 40.95s/it]\n"
     ]
    }
   ],
   "source": [
    "_ = download_s3_files(unfinished_s3_paths, unfinished_paths, n_cores=32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:41:19.221238Z",
     "iopub.status.busy": "2025-10-26T01:41:19.221076Z",
     "iopub.status.idle": "2025-10-26T01:41:23.148598Z",
     "shell.execute_reply": "2025-10-26T01:41:23.148050Z",
     "shell.execute_reply.started": "2025-10-26T01:41:19.221221Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jobs to be done 19 19\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  1.52it/s]\n"
     ]
    }
   ],
   "source": [
    "# # deleted files are at: deleted; try to get them as well\n",
    "finished_paths = os.listdir(JSON_DIR)\n",
    "finished_paths_set = set(finished_paths)\n",
    "unfinished_s3_paths = [\n",
    "    path for path in s3_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "unfinished_paths = [\n",
    "    path for path in local_paths if os.path.basename(path) not in finished_paths_set\n",
    "]\n",
    "print(\"jobs to be done\", len(unfinished_paths), len(unfinished_s3_paths))\n",
    "unfinished_deleted_s3_paths = [\n",
    "    path.replace(\"/uploads/\", \"/deleted/\") for path in unfinished_s3_paths\n",
    "]\n",
    "_ = download_s3_files(unfinished_deleted_s3_paths, unfinished_paths, n_cores=32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:41:23.149384Z",
     "iopub.status.busy": "2025-10-26T01:41:23.149228Z",
     "iopub.status.idle": "2025-10-26T01:41:23.151918Z",
     "shell.execute_reply": "2025-10-26T01:41:23.151506Z",
     "shell.execute_reply.started": "2025-10-26T01:41:23.149368Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finish downloads hoot!\n"
     ]
    }
   ],
   "source": [
    "print(\"Finish downloads hoot!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Submit the annotation job"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:41:23.152517Z",
     "iopub.status.busy": "2025-10-26T01:41:23.152389Z",
     "iopub.status.idle": "2025-10-26T01:41:23.334212Z",
     "shell.execute_reply": "2025-10-26T01:41:23.333626Z",
     "shell.execute_reply.started": "2025-10-26T01:41:23.152504Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Submitted batch job 12925\n"
     ]
    }
   ],
   "source": [
    "!sbatch /home/tony/Work/tony/Preference/sbatch_audio_quality_filter 0 {data_file}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-26T01:41:23.335027Z",
     "iopub.status.busy": "2025-10-26T01:41:23.334870Z",
     "iopub.status.idle": "2025-10-26T01:41:23.337637Z",
     "shell.execute_reply": "2025-10-26T01:41:23.337213Z",
     "shell.execute_reply.started": "2025-10-26T01:41:23.335012Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finally!\n"
     ]
    }
   ],
   "source": [
    "print(\"Finally!\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.15"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
