Skip to content

Commit 24a7a87

Browse files
committed
Download models
1 parent b07ee26 commit 24a7a87

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Advanced-RVC.ipynb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,67 @@
157157
"execution_count": null,
158158
"outputs": []
159159
},
160+
{
161+
"cell_type": "code",
162+
"source": [
163+
"#@title Download models\n",
164+
"\n",
165+
"import os\n",
166+
"import requests\n",
167+
"from tqdm import tqdm\n",
168+
"\n",
169+
"def download_model(url, model_name):\n",
170+
" \"\"\"Downloads a model from a URL to a specified directory.\n",
171+
"\n",
172+
" Args:\n",
173+
" url: The URL of the model to download.\n",
174+
" model_name: The name of the model.\n",
175+
" \"\"\"\n",
176+
"\n",
177+
" model_dir = os.path.join(\"models\", model_name)\n",
178+
" os.makedirs(model_dir, exist_ok=True)\n",
179+
" zip_path = os.path.join(model_dir, \"model.zip\")\n",
180+
"\n",
181+
" try:\n",
182+
" response = requests.get(url, stream=True)\n",
183+
" response.raise_for_status() # Raise an exception for bad status codes\n",
184+
"\n",
185+
" total_size = int(response.headers.get('content-length', 0))\n",
186+
" block_size = 1024 # 1 KB\n",
187+
" progress_bar = tqdm(total=total_size, unit='iB', unit_scale=True)\n",
188+
"\n",
189+
" with open(zip_path, 'wb') as file:\n",
190+
" for data in response.iter_content(block_size):\n",
191+
" progress_bar.update(len(data))\n",
192+
" file.write(data)\n",
193+
" progress_bar.close()\n",
194+
"\n",
195+
" if total_size != 0 and progress_bar.n != total_size:\n",
196+
" print(\"ERROR, something went wrong\")\n",
197+
"\n",
198+
" print(f\"Model '{model_name}' downloaded successfully to {model_dir}\")\n",
199+
"\n",
200+
" except requests.exceptions.RequestException as e:\n",
201+
" print(f\"Error downloading model: {e}\")\n",
202+
" except Exception as e:\n",
203+
" print(f\"An unexpected error occurred: {e}\")\n",
204+
"\n",
205+
"\n",
206+
"# Example usage\n",
207+
"model_url = \"\" #@param {type:\"string\"}\n",
208+
"model_name = \"\" #@param {type:\"string\"}\n",
209+
"# Replace with your desired model name\n",
210+
"\n",
211+
"\n",
212+
"download_model(model_url, model_name)"
213+
],
214+
"metadata": {
215+
"cellView": "form",
216+
"id": "qk74gqJqEB_A"
217+
},
218+
"execution_count": null,
219+
"outputs": []
220+
},
160221
{
161222
"cell_type": "code",
162223
"source": [

0 commit comments

Comments
 (0)