{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.gpt import chirp_v2_5 as chirp_v3\n",
    "from suno_utils.tasks.ditto_v2 import preload_models\n",
    "from suno_utils.tasks.ditto_v2 import encode_overlap as encode, SAMPLE_RATE, load_model\n",
    "from suno_utils.utils.clip import SunoClip\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "model_filepath = \"s3://suno-data/minz/models/ditto_v2_epoch_57.pt\"\n",
    "model_path = chirp_v3._get_model_if_needed(model_filepath)\n",
    "_ = preload_models(\n",
    "    model_filepath=model_path,\n",
    ")\n",
    "ditto = load_model()[\"model\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "PREF_PATH = \"/home/tony/Data/Preference/auk_t1/interesting_clips_auk_t1_20250604.pkl\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_pickle(PREF_PATH)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "for col_name in df.columns:\n",
    "    print(col_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# lets look at fewer columns\n",
    "df = df[\n",
    "    [\n",
    "        \"pos_preference\",\n",
    "        \"neg_preference\",\n",
    "        \"diff_preference\",\n",
    "        \"preference\",\n",
    "        \"s3_id\",\n",
    "        \"metadata\",\n",
    "    ]\n",
    "]\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# get a sample generation and make a clip\n",
    "s3_id = df.sample(n=1)[\"s3_id\"].iloc[0]\n",
    "print(s3_id)\n",
    "clip = SunoClip(s3_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# prep it for ditto and encode\n",
    "task = \"self_sim\"\n",
    "audio = clip.audio()\n",
    "audio = audio.convert(sample_rate=SAMPLE_RATE, n_channels=1, byte_width=2)\n",
    "encoding = encode([audio], task=task)[0]\n",
    "print(audio.array_float.shape, encoding.shape)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "suno_clean",
   "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"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
