{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0d83737",
   "metadata": {},
   "outputs": [],
   "source": [
    "# !nvidia-smi\n",
    "# !echo $HOSTNAME"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fed7c348",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"4\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "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, generate, load_audio, load_clip, shuffle_lyrics, adjust_speed, np, Audio, \n",
    "    split_stems, upsample_crossfade, upsample\n",
    ")\n",
    "\n",
    "gpt_model_fp = \"/app2/suno/checkpoints/2025-06-14_06-26-35/last_ckpt_infer.pt\"  # mistery\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-26_17-57-55/last_ckpt_infer.pt\"  # bluejay chef+14\n",
    "# gpt_model_fp = \"/app/suno/checkpoints/2025-05-21_22-39-00/last_ckpt_infer.pt\"  # bluejay chef+11\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 = \"/app2/suno/checkpoints/2025-06-13_01-56-50_s152/last_ckpt_infer.pt\"  # newest with degrade\n",
    "diff_model_fp = \"/app2/suno/modal/models/tony/tmp/diff/v45_2b_step_2mil_ft_8k_infill_apr21_d3_v10.pt\"  # ahi prod\n",
    "\n",
    "_ = setup_models(gpt_model_fp, diff_model_fp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "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 = \"big room trance\"\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",
    "# tags = \"This energetic fusion opens with a vibrant dhol loop and tabla textures layered beneath lush R&B keys and atmospheric pads. Verses alternate between melodic pop hooks and rapid-fire rap, supported by syncopated bhangra percussion and sharp bass. Choruses burst with Bollywood-style strings and brass, interwoven with claps and modern trap hi-hats, creating a powerful, irresistible groove before dropping into sleek breakdowns highlighting traditional instruments intertwined with contemporary synth flourishes.\"\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/halo.wav\")\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/eminem_doctor.wav\")\n",
    "# audio_playlist_1 = load_audio(\"c492fb16-3075-4b7d-897a-47075f0254f2\").get_segment(from_s=20, to_s=60)\n",
    "# audio_playlist_2 = load_audio(\"14aea8e5-4ea1-46f1-97fc-173d6cb713b3\").get_segment(from_s=20, to_s=60)\n",
    "# audio_playlist_3 = load_audio(\"6410f389-dd7f-4dac-8b0d-292d34463d4f\").get_segment(from_s=20, to_s=60)\n",
    "# audio_playlist_1 = load_audio(\"ef47091f-dd47-4c27-a0ca-006260aa6869\").get_segment(from_s=20, to_s=60)\n",
    "# audio_playlist_2 = load_audio(\"3b617e13-c441-413e-a606-9ced85d12d46\").get_segment(from_s=20, to_s=60)\n",
    "# audio_playlist_3 = load_audio(\"3ab0947c-0dd1-4bd0-959c-29f7aecb22a1\").get_segment(from_s=20, to_s=60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b173c6c",
   "metadata": {},
   "outputs": [],
   "source": [
    "out_semantic, out_audio = generate(\n",
    "    text,\n",
    "    tags,\n",
    "#     audio_history=audio_history,\n",
    "#     audio_artist=audio_artist,\n",
    "#     audio_cover=audio_cover,\n",
    "#     audio_vocals=audio_vocals,\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_max_steps=None,\n",
    "#     gpt_cfg_coef_tags=1.0,\n",
    "#     gpt_cfg_coef_tags_max_steps=25*30,\n",
    "#     gpt_cfg_coef_audio=2.0,\n",
    "#     max_gen_duration_s=4*60, \n",
    "#     n_skip_semantic=4,\n",
    "#     control_tags=\"{duration:60}\",\n",
    "#     control_tags=\"{hook_offset:random}\",\n",
    "    return_semantic=True,\n",
    "#     seed=1,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d4f8fc1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# out_audio_2 = upsample(out_semantic, text=text, tags=tags, noise_ctx_level=1.0, ignore_history_every=1)\n",
    "# # cd ~/code/glockenspiel && git checkout gk_crossfade\n",
    "# # https://github.com/suno-ai/glockenspiel/pull/new/gk_crossfade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07efef8b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# out_audio_3 = upsample_crossfade(out_semantic, text=text, tags=tags)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2dd1f7c7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c00ec749",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2dddf331",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import json\n",
    "from suno_utils.utils.s3 import read_from_s3\n",
    "\n",
    "# load the test clip here\n",
    "#item = work_items[10]\n",
    "#item_id = \"c75e6dc3-de5a-4a18-aae4-a24ac25dc850\"\n",
    "#item_id = \"fce5c7de-27db-409c-be2b-8ace15720c2b\"\n",
    "#item_id = \"1ec51ef1-378e-4f33-94a5-05c9b1e1448f\" \n",
    "#item_id = \"1210dc12-03d2-48fc-a51c-87d02b3517c5\" #long\n",
    "#item_id = \"ea86b583-913a-45df-9401-c48f01f4caf3\"\n",
    "#item_id = \"dfcbd035-2b9d-4c43-89ba-39411d0c6e43\"\n",
    "#item_id = \"a0438b2e-c6d2-4119-8bc6-863949b04d76\"\n",
    "#item_id = \"0ccb861e-8fc9-4a58-bc3f-e7c3e0bbd18b\"\n",
    "#item_id = \"b37c1380-7ad5-4a1b-8608-aabc26af42a1\"\n",
    "#item_id = \"44e11913-4b48-4f31-9c26-5bb19105b474\" # dna\n",
    "#item_id = \"0b0268b5-1599-4888-985f-46de37d42cd0\" # feels so good\n",
    "#item_id = \"1025518a-ace8-41c9-b979-13b07ae4d301\"\n",
    "#item_id = \"7868c62c-0d0d-4355-a35f-8a5d8ecc234f\"\n",
    "#item_id = \"1bb8ea30-31a2-43a6-8b94-ba15fe1e4eff\"\n",
    "#item_id = \"ace679d6-0c59-4d6f-893f-951b80f33490\"\n",
    "#item_id = \"6c425fb1-0194-4995-82e0-dc2764be8bb3\"\n",
    "#item_id = \"e88fc58b-3e7f-4401-aae1-62207d89e140\"\n",
    "#item_id = \"b0d17aa0-8cb6-4db3-89ac-2c89d89f742a\"\n",
    "#item_id = \"26824a36-a837-4cca-95a9-e9458868af05\"\n",
    "#item_id = \"04110bb9-bb25-4afb-9cd6-7b987f3510a4\"\n",
    "#item_id = \"d09b0bb9-20cc-4228-b92a-700f884c84dc\"\n",
    "#item_id = \"a06329ca-9453-4730-82b6-f48576fe4530\"\n",
    "item_id = \"13792213-e460-4e2f-b1db-2e7894ae6221\"\n",
    "#item_id = \"de5e5ecd-2616-4f3f-a856-392111badc3f\"\n",
    "\n",
    "print(item_id)\n",
    "# load the semantic codes from s3\n",
    "s3_filepath = f\"s3://suno-data-uploads/studio/uploads/{item_id}.npz\"\n",
    "\n",
    "try:\n",
    "    data = read_from_s3(s3_filepath, read_f=np.load)\n",
    "except Exception as e:\n",
    "    print(f\"Error loading {s3_filepath}: {e}\")\n",
    "\n",
    "if \"v3.0_raw\" in data:\n",
    "    codes = data[\"v3.0_raw\"]\n",
    "elif \"v3.5_raw\" in data:\n",
    "    codes = data[\"v3.5_raw\"]\n",
    "elif \"v4.0_raw\" in data:\n",
    "    codes = data[\"v4.0_raw\"]\n",
    "elif \"v5.0_raw\" in data:\n",
    "    codes = data[\"v5.0_raw\"]\n",
    "else:\n",
    "    raise ValueError(\"No codes found\")\n",
    "\n",
    "semantic_codes =codes[:, 0]\n",
    "# semantic_codes = semantic_codes[:3000]\n",
    "print(semantic_codes.shape)\n",
    "\n",
    "# load the vae\n",
    "vae_data_filepath = f\"s3://suno-data-uploads/studio/uploads/{item_id}_vae.npz\"\n",
    "vae_data = read_from_s3(vae_data_filepath, read_f=np.load)\n",
    "print()\n",
    "\n",
    "#tags_str = item[\"tags\"]\n",
    "\n",
    "#if tags_str is None:\n",
    "#    tags_str = \"\"\n",
    "#lyrics = item[\"text\"]\n",
    "\n",
    "os.system(f\"aws s3 cp s3://suno-data-uploads/studio/uploads/{item_id}_hoot.json text_data.json\")\n",
    "text_data = open(\"text_data.json\", \"r\", encoding=\"utf-8\").read()\n",
    "aligned_lyrics = json.loads(text_data)\n",
    "print(aligned_lyrics)\n",
    "\n",
    "tags = \"\"\n",
    "\n",
    "lyrics = \"\"\n",
    "for elem in aligned_lyrics:\n",
    "    if \"word\" in elem:\n",
    "        lyrics += elem[\"word\"]\n",
    "\n",
    "text = lyrics\n",
    "tags = \"\"\n",
    "clip_sem_arr = semantic_codes\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2817b88f",
   "metadata": {},
   "source": [
    "### Upsample degrade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6349be81",
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://suno.com/song/be9e3bef-ccb9-4ce9-9949-ca585c9bfbaf\n",
    "clip_sem_arr, clip_audio = load_clip(\"be9e3bef-ccb9-4ce9-9949-ca585c9bfbaf\")\n",
    "text = \"[Intro: short acoustic guitar solo]\\n[Plucking sinister arpeggios in the key of D minor with squeaking artefacts depicting a window being cleaned]\\n\\n⸻\\n\\n[Verse: gravelly baritone male vocals low and menacing with an irritated edge]\\n[Acoustic guitar aggressive pizzicato, joined by stomping thrash drums]\\n\\nThat makes the twelfth damn week\\nThe twelfth damn week in a row - almost\\nEvery time I’m volume trainin’ chest\\nYou come in with your verbal fuckin’ reek\\nMakes me long for the eternal goddamned rest\\n[Deathgrowl:] Ooh!\\n\\n⸻\\n\\n[Thrash guitar enters with the force of a sledgehammer, with immersive downpicking and distortion creating a catchy and menacing rhythm in D minor]\\n\\n⸻\\n\\n[Verse: gravelly baritone male vocals emotive and angry]\\n[Electric guitar strumming hard on notes 1 & 3 in the key of D minor, bass guitar accompanying in aggressive pizzicato]\\n\\nJust clean the damn windows!\\nWhy d’you have to talk all your shit?\\nAll your damn conspiracy shit\\nThe earth’s god-damn round - you fuckin’ tit\\n\\nSpeakin’ of tits - mine need to fuckin’ grow\\nSo please - please…\\nJust clean the damn window and go\\n\\n⸻\\n\\n[All instruments hold back]\\n\\n⸻\\n\\n[Pre-Chorus: gravelly baritone male vocals low and threatening]\\n[All instruments building progressively for chorus]\\nI resisted doin’ this\\nFor months and god-damned months\\nBut your interruptions just took\\nThe last of my fuckin’ piss…\\n\\n⸻\\n\\n[Rhythmic stutter effect on drums and guitars]\\n\\n⸻\\n\\n[Chorus: gravelly baritone male vocals loud and aggressive with theatrical flair, gang backing]\\n[All instruments high energy, thrash guitar at full immersion in d minor, bass guitar slapping hard on notes 1&3, thrash drums stomping, acoustic guitar pizzicato]\\n\\nGod damn you!\\nFuckin’ Ramsay!\\nStayin’ so long - talkin’ poo\\nYour face like the underside - of my shoe\\nTakin’ so much time out my day\\nI think you must be fuckin’ - Gay!\\nAnd it’s true!\\nWhat you’d probably say…\\n\\n⸻\\n\\n[Hook: gravelly baritone male vocals low and taunting]\\n[All instruments building for drop section]\\n\\nI’m a bit of a cunt!\\n[Character monologue - spoken word] But your mouth still needs stuffed with your own fuckin’ windex pump\\n\\n⸻\\n\\n[Drop section: long instrumental solo]\\n[Heavy thrash guitars slam into full force with heavy down picking and distortion, bass guitars slapping aggressively on Beats 1 & 3, thrash drums stomping as acoustic guitar plucks a memorable hook]\\n\\n⸻\\n\\n[Verse: gravelly baritone male vocals emotive and angry]\\n[All instruments chugging a heavy rhythm in D minor]\\n \\nI try not to let it bother me\\nWhen you come in thinkin’ my times free\\nBut you go on and on and on and on and on\\nSo long I just end up wishing you were gone\\nOr maybe I should fuckin’ flee\\n[Deathgrowl:] Ooh!\\n\\n⸻\\n\\n[Bridge: gravelly baritone male vocals sinister and taunting]\\n[All instruments in dissonant build for final chorus]\\n\\nThe same damn conversation\\nEvery fuckin’ week\\nSeems your outlook on our situation’s\\nPretty fuckin’ bleak\\nNot that I necessarily disagree\\n\\nBut your dull verbal barrage\\nHas me on my fuckin’ \\n\\n[Bridge:  gravelly  baritone  male  vocals  sinister  and  taunting]\\n[All instruments in dissonant build for final chorus]\\n\\nThe same damn conversation\\nEvery fuckin’ week\\nSeems your outlook on our situation’s\\nPretty fuckin’ bleak\\nNot that I necessarily disagree\\n\\nBut your dull verbal barrage\\nHas me on my fuckin’ knee\\nBeggin’ please…\\nPlease\\nJust shut up - I don’t care about your god-damn garage\\nGive me fuckin’ - peace!\\n\\n⸻\\n\\n[Final Chorus: gravelly baritone male vocals loud and aggressive with theatrical flair, gang backing]\\n[All instruments high energy, thrash guitar at full immersion in d minor, bass guitar slapping hard on notes 1&3, thrash drums stomping, acoustic guitar pizzicato]\\n\\nGod damn you!\\nFuckin’ Ramsay!\\nStayin’ so long - talkin’ poo\\nYour face like the underside - of my shoe\\nTakin’ so much time out my day\\nI think you must be fuckin’ - Gay!\\nAnd it’s true!\\nWhat you’d probably say…\\n\\n⸻\\n\\n[Final Hook: gravelly baritone male vocals low and taunting]\\n[All instruments building for final drop section]\\n\\nI’m a bit of a cunt!\\n[Character monologue - spoken word] But your mouth still needs stuffed with your own fuckin’ windex pump\\n\\n⸻\\n\\n[Final Drop section: long instrumental solo]\\n[Heavy thrash guitars slam into full force with heavy down picking and distortion, bass guitars slapping aggressively on Beats 1 & 3, thrash drums stomping as acoustic guitar plucks a memorable hook]\"\n",
    "tags = \"A swaggering Western metal ballad with a gravelly male vocal, laced with dark seduction and outlaw charm, It begins slow and sultry—twangy acoustic guitar rides atop moody ambient wind textures and la\"\n",
    "clip_audio.play()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6fb0a356",
   "metadata": {},
   "outputs": [],
   "source": [
    "_ = upsample([clip_sem_arr], text=text, tags=tags, noise_ctx_level=0.5, ignore_history_every=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "327d0a95",
   "metadata": {},
   "outputs": [],
   "source": [
    "_ = upsample_crossfade([clip_sem_arr], text=text, tags=tags)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ea0848a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef73ae95",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42f11ed4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "255136ab",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62e8d239",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5991637",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c45714e8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "ec617914",
   "metadata": {},
   "source": [
    "### special test cases"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "efc09d5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# # check retained raw instrument\n",
    "# out_audio = infer(\n",
    "#     \"\",\n",
    "#     \"drum loop\",\n",
    "#     max_gen_duration_s=30, \n",
    "# )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4df41a02",
   "metadata": {},
   "outputs": [],
   "source": [
    "# # check genre drift\n",
    "# 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": [
    "# # 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": "3a8ff5bb",
   "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": null,
   "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": null,
   "id": "a250d264",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.tasks.hoot import encode as encode_hoot, preload_models as preload_models_hoot\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": "821deaed",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "385bf55e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "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": null,
   "id": "3b38670d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.utils.text import read_jsonl\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",
    "lll = []\n",
    "for m in tqdm.tqdm(\n",
    "    metas_covers + metas_deezer + metas_discogs_subset + metas_genius + \n",
    "    metas_imslp + metas_karaoke + metas_musdb + metas_ytm + 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",
    "lll2 = []\n",
    "for m in tqdm.tqdm(\n",
    "    metas_covers + metas_deezer + metas_discogs_subset + metas_genius + \n",
    "    metas_imslp + metas_karaoke + metas_musdb + metas_ytm + metas_pond5 + 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",
    "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",
    "metas = read_from_s3(\"s3://suno-data/datasets/harvest/who_sampled/sample.jsonl\", read_f=read_jsonl)\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": null,
   "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": null,
   "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(len([m for m in metas if m[0][\"youtube\"] in available_ids and m[1][\"youtube\"] in available_ids]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b536451",
   "metadata": {},
   "outputs": [],
   "source": [
    "lll = [m for m in metas if m[0][\"youtube\"] not in available_ids and m[1][\"youtube\"] not in available_ids]"
   ]
  },
  {
   "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",
    "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_diff",
   "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.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
