{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a0d83737",
   "metadata": {},
   "outputs": [],
   "source": [
    "# !nvidia-smi\n",
    "# !echo $HOSTNAME"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fed7c348",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "11554eb8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# # create a model mix\n",
    "# mix_ratio = 0.5  # how much of raw to use\n",
    "# import torch\n",
    "# from collections import OrderedDict\n",
    "# cpd = \"/app/suno/checkpoints/\"\n",
    "# sd1 = torch.load(f\"{cpd}2025-05-21_22-39-00/last_ckpt_infer.pt\", map_location=\"cpu\", weights_only=True)\n",
    "# sd2 = torch.load(f\"{cpd}2025-05-19_13-46-02/last_ckpt_infer.pt\", map_location=\"cpu\", weights_only=True)\n",
    "# assert set(sd1.keys()) == set(sd2.keys())\n",
    "# sd1[\"model\"] = {k: sd1[\"model\"][k] * mix_ratio + sd2[\"model\"][k] * (1 - mix_ratio) for k in sd1[\"model\"].keys()}\n",
    "# torch.save(sd1, \"/app/suno/tmp/neonsky_05.pt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83ceb330",
   "metadata": {},
   "outputs": [],
   "source": [
    "from local_lyrics import *\n",
    "from local_helpers import (\n",
    "    setup_models,\n",
    "    infer,\n",
    "    load_audio,\n",
    "    shuffle_lyrics,\n",
    "    adjust_speed,\n",
    "    np,\n",
    "    Audio,\n",
    "    split_stems,\n",
    ")\n",
    "\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-26_17-57-55/last_ckpt_infer.pt\"  # bluejay chef+14\n",
    "gpt_model_fp = (\n",
    "    \"/app/suno/checkpoints/2025-05-21_22-39-00/last_ckpt_infer.pt\"  # bluejay chef+11\n",
    ")\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-21_14-11-12/last_ckpt_infer.pt\"  # bluejay dpo\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-31_07-05-35/last_ckpt_infer.pt\"  # bluejay dpo-light\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-19_13-46-02/last_ckpt_infer.pt\"  # bluejay sft\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-17_02-36-28/last_ckpt_infer.pt\"  # bluejay\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-18_12-16-03/last_ckpt_infer.pt\"  # auk chef\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-03_04-07-02/last_ckpt_infer.pt\"  # auk prod\n",
    "# gpt_model_fp = \"/app/suno/tmp/3b_orig_fix.pt\"  # 3b\n",
    "# gpt_model_fp = \"/home/tony/Data/checkpoints/gpt/test_add_15.pt\"  # chef+vector_15\n",
    "\n",
    "# diff_model_fp = \"/app/suno/checkpoints/2025-05-23_05-21-32_s6113/last_ckpt_infer.pt\"  # ahi chef\n",
    "diff_model_fp = \"/app2/suno/modal/models/tony/tmp/diff/v45_2b_step_2mil_ft_8k_infill_apr21_d3_v10.pt\"  # ahi chef\n",
    "# diff_model_fp = \"/app/suno/tmp/v45_2b_step_2mil_ft_8k_infill_apr21_t1_18_cs0.pt\"  # ahi prod\n",
    "\n",
    "_ = setup_models(gpt_model_fp, diff_model_fp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "17c012a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "#############\n",
    "### text  ###\n",
    "#############\n",
    "\n",
    "text = \"\"\n",
    "# text = \"[instrumental]\"\n",
    "# text = text_carrots\n",
    "# text = text_calm_down\n",
    "# text = text_calm_down2\n",
    "# text = text_summertime\n",
    "# text = text_good_to_me\n",
    "# text = text_titanic\n",
    "# text = text_rise\n",
    "# text = text_real\n",
    "# text = text_damage\n",
    "# text = text_halo\n",
    "# text = text_country\n",
    "# text = text_raindrops\n",
    "\n",
    "# text = shuffle_lyrics(text, ngrams=1)\n",
    "\n",
    "#############\n",
    "### tags  ###\n",
    "#############\n",
    "\n",
    "tags = \"\"\n",
    "# tags = \"country, bluegrass, fiddle\"\n",
    "# tags = \"drum loop\"\n",
    "# tags = \"epic trailer, dark, instrumental, violin, powerful, hero\"\n",
    "# tags = \"pop\"\n",
    "# tags = \"pop, soul, r&b, power ballad\"\n",
    "# tags = \"bluegrass\"\n",
    "# tags = \"gregorian chant\"\n",
    "# tags = \"gospel\"\n",
    "# tags = \"edm, club, trance, violin, female vocals, ethereal, techno\"\n",
    "# tags = \"A high-energy fusion of pulsing EDM techno beats and twangy bluegrass fiddle riffs, this track blends driving four-on-the-floor kick drums with fast, melodic fiddle solos and rhythmic banjo plucks. Imagine a late-night rave deep in Appalachian hills—glitchy synths, soaring fiddle lines, and a drop that stomps like a barn dance gone cyberpunk.\"\n",
    "# tags = \"speedcore\"\n",
    "# tags = \"scotish bagpipes, funeral, march\"\n",
    "# tags = \"A melancholic country song featuring prominent pedal steel guitar. Emotive female folksy vocals. The song delivers a sense of longing and sentimentality.\"\n",
    "# tags = \"An edm track for a club featuring a prominent violin throughout.\"\n",
    "# tags = \"female vocals, ballad, piano, powerful\"\n",
    "# tags = \"bubblegum pop\"\n",
    "# tags = \"Gregorian Chant, Hymns, Christian, ethereal, female vocalist, medieval, atmospheric, spiritual, melodic, choral, peaceful, hypnotic, hymn, meditative, minimalistic, soothing, religious, soft, longing, dense, melancholic, mysterious, repetitive, acoustic\"\n",
    "# tags = \"Two-track instrumental featuring ambient nature sounds and rhythmic clanging, followed by sinister synthesizer music and buzzing electric circuit.\"\n",
    "# tags = \"Country, southern accent, deep south, raspy vocals\"\n",
    "# tags = \"Americana, Country, Contemporary Folk, lonely, sombre, introspective, longing, acoustic, melodic, bittersweet, pastoral, poetic, melancholic, depressive, pessimistic, dark, passionate\"\n",
    "# tags = \"Contemporary R&B, Pop Rap, Alternative R&B, Trap, nocturnal, female vocalist, aquatic, alcohol, male vocalist, sexual\"\n",
    "# tags = \"Pop Soul, Neo-Soul, Jazz Pop, Brill Building, Twist, drugs, female vocalist, rebellious, alcohol, rhythmic, depressive, introspective, passionate, sarcastic, melodic, hedonistic, anthemic\"\n",
    "# tags = \"power ballad, female vocals, male vocals, pop, rap, hip-hop, emotive, powerful\"\n",
    "# tags = \"2023, Melodic Techno, Future Rave, Melodic House, rhythmic, atmospheric, instrumental\"\n",
    "# tags = \"2023, Dance-Pop, Electro House, Festival Progressive House, Electropop, Dutch House, passionate, female vocalist, triumphant, introspective, energetic, anthemic, rhythmic, sentimental\"\n",
    "# tags = \"Dance-Pop and Electro House track built ontop of a repeated catchy saxophone loop.\"\n",
    "# tags = \"passionate, raspy vocals, powerful delivery, female, pop\"\n",
    "# tags = \"Pop, female vocals, orchestra\"\n",
    "# tags = \"Indie Pop, Indietronica, Art Pop, Progressive Pop, Post-Punk Revival, Indietronica, breakup, bittersweet, anxious, male vocalist, melancholic, quirky, melodic, cryptic, playful, progressive, energetic, depressive, warm, violence, longing, passionate, sombre, love, surreal, rhythmic, disturbing, abstract\"\n",
    "# tags = \"Filmi, Pop Rock, Electronic, Downtempo, optimistic, philosophical, humorous, urban, female vocalist, happy, uplifting, melodic, passionate, male vocalist\"\n",
    "# tags = \"Hardcore Hip Hop, Film Soundtrack, Conscious Hip Hop, Rap Rock, anxious, triumphant, anthemic, passionate, male vocalist, suspenseful, rhythmic, introspective, urban, optimistic, uplifting, energetic, aggressive, epic, crime, vulgar, nocturnal, conscious, longing, angry, alienation\"\n",
    "# tags = \"epic film orchestral\"\n",
    "# tags = \"female vocals; This track start off quiet and slow featuring string instruments including a violin. It then builds into an energetic chorus with drums and trumpets.\"\n",
    "# tags = \"trumpet, instrumental\"\n",
    "# tags = \"bag pipes, scottish, military, bagpipes\"\n",
    "# tags = \"epic trailer music,  female vocalizations,  instrumental,  dark,  orchestra,  violin\"\n",
    "# tags = \"orchestra, symphony\"\n",
    "# tags = \"Piano Concerto; Romantic; German; B-Flat Major; Dramatic; Virtuosic; 48khz; high-quality\"\n",
    "# tags = \"A fusion of Baroque elegance and modern dubstep intensity, where intricate harpsichord melodies and orchestral strings intertwine with thunderous bass drops, glitchy distortions, and electrifying rhythmic shifts. The result is a dramatic contrast of refined classical ornamentation and raw electronic energy.\"\n",
    "# tags = \"piano concerto\"\n",
    "# tags = \"The piece that opens with a soft, flute-led melody gently awakening the senses, conjuring the warmth of a sunrise over tranquil hills. The orchestra gradually swells with smooth strings and light percussion, evoking a blossoming sense of optimism and renewed energy. A graceful interplay of woodwinds and strings concludes on a delicate, uplifting note that captures the fresh promise of morning.\"\n",
    "# tags = \"A stirring, festive march led by bold brass fanfares and triumphant rhythms that command attention right from the start. Let snappy snare drums and buoyant woodwinds propel the music forward with an infectious energy. The piece culminates in a grand, celebratory finale that invites enthusiastic clapping and cheering.\"\n",
    "# tags = \"Pop Rap, Contemporary R&B, Pop Rock, male vocalist, female vocalist, melodic, angry, love, passionate, vulgar, breakup, melancholic, sad, bittersweet, romantic, urban, anxious, serious, domestic\"\n",
    "# tags = \"rap, chicago rap, high pitch vocal sample, beat switches, surprising\"\n",
    "\n",
    "##############\n",
    "### audio  ###\n",
    "##############\n",
    "\n",
    "# audio_filepath = \"../samples/halo.wav\"\n",
    "# audio_filepath = \"../samples/corn_chase.mp3\"\n",
    "# audio_filepath = \"../samples/martin2.m4a\"\n",
    "# audio_filepath = \"../samples/can_it_be_real.mp3\"\n",
    "# audio_filepath = \"../samples/calm_down_vocals.mp3\"\n",
    "# audio_filepath = \"../samples/halo_vocals.wav\"\n",
    "# audio_filepath = \"../samples/titanic_vocals.wav\"\n",
    "# audio_filepath = \"../samples/calm_down_instrumental.mp3\"\n",
    "\n",
    "# audio_artist = load_audio(\"../samples/eminem_doctor.wav\").get_segment(to_s=60*2).get_segment(from_s=32, to_s=52)\n",
    "# audio_cover = load_audio(\"../samples/titanic.mp3\")\n",
    "# audio_vocals = load_audio(\"../samples/titanic_vocals.wav\")\n",
    "# audio_instrumental = load_audio(\"../samples/calm_down_instrumental.mp3\")\n",
    "# audio_vocals, audio_instrumental = split_stems(\"../samples/damage.mp3\")\n",
    "audio_playlist_1 = load_audio(\"c492fb16-3075-4b7d-897a-47075f0254f2\").get_segment(\n",
    "    from_s=0, to_s=60\n",
    ")\n",
    "audio_playlist_2 = load_audio(\"14aea8e5-4ea1-46f1-97fc-173d6cb713b3\").get_segment(\n",
    "    from_s=0, to_s=60\n",
    ")\n",
    "audio_playlist_3 = load_audio(\"6410f389-dd7f-4dac-8b0d-292d34463d4f\").get_segment(\n",
    "    from_s=0, to_s=60\n",
    ")\n",
    "# audio_playlist_1 = load_audio(\n",
    "#     \"e1dc6ce5-3fbb-4eff-b1d5-416df6ff8b57\"\n",
    "# )  # .get_segment(from_s=0, to_s=60)\n",
    "# audio_playlist_2 = load_audio(\n",
    "#     \"990a1206-1769-4f25-8276-85072e7dc381\"\n",
    "# )  # .get_segment(from_s=0, to_s=60)\n",
    "# audio_playlist_3 = load_audio(\n",
    "#     \"71736ae2-0085-42ab-88df-25fb0cf99630\"\n",
    "# )  # .get_segment(from_s=0, to_s=60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1ce6ded",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_audio_vs_cfg = {}\n",
    "for cfg_audio in [0.5, 1.0, 1.5, 2.0, 3.0, 4.0]:\n",
    "    out_audio = infer(\n",
    "        \"\",  # text\n",
    "        \"\",  # tags\n",
    "        #     audio_history=audio_history,\n",
    "        #     audio_artist=audio_artist,\n",
    "        #     audio_cover=audio_cover,\n",
    "        #     audio_vocals=audio_vocals_degraded,\n",
    "        #     audio_instrumental=audio_instrumental,\n",
    "        audio_playlist=[audio_playlist_1, audio_playlist_2, audio_playlist_3],\n",
    "        gpt_cfg_coef_audio=cfg_audio,\n",
    "        max_gen_duration_s=2 * 60,\n",
    "    )\n",
    "    output_audio_vs_cfg[cfg_audio] = out_audio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0f50124f",
   "metadata": {},
   "outputs": [],
   "source": [
    "for cfg_cut, output_audio in output_audio_vs_cfg.items():\n",
    "    for i, audio_chunk in enumerate(output_audio):\n",
    "        audio_chunk.write_wav(f\"output_audio_vs_cfg_{cfg_cut}_{i}.wav\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a5b8a07",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"Done!!\")\n",
    "BREAK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6149ec1f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# out_audio = infer(\n",
    "#     \"\",  # text\n",
    "#     \"symphony, orchestra, classical, romantic, dramatic, virtuosic, 48khz, high-quality\",  # tags\n",
    "#     #     audio_history=audio_history,\n",
    "#     #     audio_artist=audio_artist,\n",
    "#     #     audio_cover=audio_cover,\n",
    "#     #     audio_vocals=audio_vocals_degraded,\n",
    "#     #     audio_instrumental=audio_instrumental,\n",
    "#     audio_playlist=[audio_playlist_1, audio_playlist_2, audio_playlist_3],\n",
    "#     #     vocals_noise_lvl=0.2,\n",
    "#     #     gpt_cfg_coef=1.2,\n",
    "#     #     gpt_cfg_coef_tags=2.5,\n",
    "#     #     gpt_cfg_coef_max_steps=None,\n",
    "#     #     gpt_cfg_coef_tags_max_steps=25*30,\n",
    "#     gpt_cfg_coef_audio=4.0,\n",
    "#     max_gen_duration_s=2 * 60,\n",
    "#     #     n_skip_semantic=4,\n",
    "#     #     control_tags=\"{duration:60}\",\n",
    "#     #     control_tags=\"{hook_offset:random}\",\n",
    "# )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "efc09d5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# out_audio = infer(\n",
    "#     \"\",\n",
    "#     \"drum loop\",\n",
    "#     max_gen_duration_s=30,\n",
    "# )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4df41a02",
   "metadata": {},
   "outputs": [],
   "source": [
    "# out_audio = infer(\n",
    "#     text_rise,\n",
    "#     \"gregorian chant\",\n",
    "#     gpt_cfg_coef_tags_max_steps=25*30,\n",
    "# )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "725cc8a4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43b70787",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "ec9c0eae",
   "metadata": {},
   "source": [
    "### make swipe interface"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e2b9f34e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# out_audio[1].to_hq_mp3(\"tmp/swipe_0.mp3\")  # folk\n",
    "# out_audio[1].to_hq_mp3(\"tmp/swipe_1.mp3\")  # edm\n",
    "# out_audio[0].to_hq_mp3(\"tmp/swipe_2.mp3\")  # metal\n",
    "# out_audio[0].to_hq_mp3(\"tmp/swipe_3.mp3\")  # country"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a250d264",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.tasks.hoot import (\n",
    "    encode as encode_hoot,\n",
    "    preload_models as preload_models_hoot,\n",
    ")\n",
    "# encode(audio_arr_list, return_logits="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e41e5283",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f897c18",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "821deaed",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "385bf55e",
   "metadata": {},
   "outputs": [],
   "source": [
    "BREAK"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92a2ae5b",
   "metadata": {},
   "source": [
    "## More options"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0f9ed456",
   "metadata": {},
   "outputs": [],
   "source": [
    "# # noise augment\n",
    "# noise_lvl = 0.1\n",
    "# arr = audio_instrumental.array_float\n",
    "# arr = arr + np.random.normal(0, noise_lvl, arr.shape).astype(arr.dtype)\n",
    "# audio_instrumental = Audio.from_array_float(np.clip(arr, -1.1, 1.1), 48_000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "9b7365d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# for n in range(2):\n",
    "#     out_audio = infer(\n",
    "#         \"\",\n",
    "#         \"drum loop\",\n",
    "#         max_gen_duration_s=30,\n",
    "#         seed=n,\n",
    "#     )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "4dca0c6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# # check for memorization\n",
    "# audio_history = load_audio(\"../samples/fur_elise.mp3\").get_segment(from_s=0, to_s=10)\n",
    "# audio_history.play()\n",
    "# out_audio = infer(\n",
    "#     \"\", \"\", gpt_cfg_coef=1.0, gpt_cfg_coef_tags=0.0, max_gen_duration_s=30,\n",
    "#     audio_history=audio_history,\n",
    "# )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7f32d67",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e14cad72",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a82d23e7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41d84339",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a3c94a9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "75c295a6",
   "metadata": {},
   "source": [
    "## Playground"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfab3a36",
   "metadata": {},
   "outputs": [],
   "source": [
    "# need metas_raw.jsonl\n",
    "!aws s3 ls s3://suno-data/datasets/bundles/v4/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ceb1775",
   "metadata": {},
   "outputs": [],
   "source": [
    "!ls /app/suno/tmp/ | grep raw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "3b38670d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.utils.text import read_jsonl\n",
    "\n",
    "metas_covers = read_jsonl(\"/app/suno/tmp/raw_covers_metas.jsonl\")\n",
    "metas_deezer = read_jsonl(\"/app/suno/tmp/raw_deezer_metas.jsonl\")\n",
    "metas_discogs = read_jsonl(\"/app/suno/tmp/raw_discogs_metas.jsonl\")\n",
    "metas_discogs_subset = read_jsonl(\"/app/suno/tmp/raw_discogs_subset_metas.jsonl\")\n",
    "metas_genius = read_jsonl(\"/app/suno/tmp/raw_genius_metas.jsonl\")\n",
    "metas_imslp = read_jsonl(\"/app/suno/tmp/raw_imslp_metas.jsonl\")\n",
    "metas_karaoke = read_jsonl(\"/app/suno/tmp/raw_karaoke_metas.jsonl\")\n",
    "metas_musdb = read_jsonl(\"/app/suno/tmp/raw_musdb_metas.jsonl\")\n",
    "metas_ytm = read_jsonl(\"/app/suno/tmp/raw_youtube_music_metas.jsonl\")\n",
    "metas_pond5 = read_jsonl(\"/app/suno/tmp/raw_pond5_metas.jsonl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb5552f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tqdm\n",
    "\n",
    "lll = []\n",
    "for m in tqdm.tqdm(\n",
    "    metas_covers\n",
    "    + metas_deezer\n",
    "    + metas_discogs_subset\n",
    "    + metas_genius\n",
    "    + metas_imslp\n",
    "    + metas_karaoke\n",
    "    + metas_musdb\n",
    "    + metas_ytm\n",
    "    + metas_pond5\n",
    "):\n",
    "    if \"fur elise\" in str(m).lower().replace(\"ü\", \"u\"):\n",
    "        lll.append(m)\n",
    "len(lll)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50ff1d04",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tqdm\n",
    "\n",
    "lll2 = []\n",
    "for m in tqdm.tqdm(\n",
    "    metas_covers\n",
    "    + metas_deezer\n",
    "    + metas_discogs_subset\n",
    "    + metas_genius\n",
    "    + metas_imslp\n",
    "    + metas_karaoke\n",
    "    + metas_musdb\n",
    "    + metas_ytm\n",
    "    + metas_pond5\n",
    "    + metas_discogs\n",
    "):\n",
    "    if \"fur elise\" in str(m).lower().replace(\"ü\", \"u\"):\n",
    "        lll2.append(m)\n",
    "len(lll2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47d1d942",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "\n",
    "random.choice(lll2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "24f9cc7a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a55f8bb8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b338f6e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.utils.s3 import read_from_s3\n",
    "from suno_utils.utils.text import read_jsonl\n",
    "\n",
    "metas = read_from_s3(\n",
    "    \"s3://suno-data/datasets/harvest/who_sampled/sample.jsonl\", read_f=read_jsonl\n",
    ")\n",
    "metas = [e for e in metas if e[0][\"youtube\"] is not None and e[1][\"youtube\"]]\n",
    "len(metas)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ca651bcf",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.utils.text import read_jsonl\n",
    "\n",
    "metas_tr = read_jsonl(\"/app/suno/data/auk_v0/metas_v2_tr.jsonl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4443159e",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = len([m for m in metas_tr if len(m.get(\"artist_ids\", [])) >= 2])\n",
    "print(f\"{n:,} tracks ({n/len(metas_tr)*100:.1f}%)\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8fc7db6b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25396b00",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4db97f62",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "8e942564",
   "metadata": {},
   "outputs": [],
   "source": [
    "metas_tr = read_jsonl(\"/app/suno/data/auk_v0/metas_v2_tr.jsonl\")\n",
    "available_ids = set([m[\"id\"] for m in metas_tr])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06b79a62",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(len(metas))\n",
    "print(len([m for m in metas if m[0][\"youtube\"] in available_ids]))\n",
    "print(len([m for m in metas if m[1][\"youtube\"] in available_ids]))\n",
    "print(\n",
    "    len(\n",
    "        [\n",
    "            m\n",
    "            for m in metas\n",
    "            if m[0][\"youtube\"] in available_ids and m[1][\"youtube\"] in available_ids\n",
    "        ]\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3b536451",
   "metadata": {},
   "outputs": [],
   "source": [
    "lll = [\n",
    "    m\n",
    "    for m in metas\n",
    "    if m[0][\"youtube\"] not in available_ids and m[1][\"youtube\"] not in available_ids\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe8d490a",
   "metadata": {},
   "outputs": [],
   "source": [
    "gHXPr - GtYUk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d259701d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "\n",
    "random.choice(lll)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "841f3291",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "acee5b1a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61553d7d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e732785",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34e32861",
   "metadata": {},
   "outputs": [],
   "source": [
    "# all are pairs\n",
    "# first is the new track\n",
    "# second the old"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f4c995c",
   "metadata": {},
   "outputs": [],
   "source": [
    "lll = []\n",
    "for e in metas:\n",
    "    if e[-1][\"artist\"] is not None and \"beyon\" in e[-1][\"artist\"].lower():\n",
    "        lll.append(e)\n",
    "len(lll)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f717d2ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "lll[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1bc273b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5791d29f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0625c905",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "242acd6e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "suno_env_dev",
   "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
}
