Spaces:
Runtime error
Runtime error
File size: 3,434 Bytes
578fa37 |
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 |
import os
import json
import requests
# fetch_pretrains returns an array with the names
# download_pretrain downloads the pretrain with the name
PRETRAINS_URL = "https://raw.githubusercontent.com/TheStingerX/Ilaria-RVC-Mainline/main/tools/pretrains.json"
def fetch_pretrains():
try:
response = requests.get(PRETRAINS_URL)
if response.status_code == 200:
pretrains_data = json.loads(response.text)
return list(pretrains_data.keys())
else:
print("Failed to fetch pretrains data. Status code:", response.status_code)
return []
except Exception as e:
print("An error occurred while fetching pretrains data:", e)
return []
def download_pretrain(pretrain_name):
try:
response = requests.get(PRETRAINS_URL)
if response.status_code == 200:
pretrains_data = json.loads(response.text)
if pretrain_name in pretrains_data:
pretrain_urls = pretrains_data[pretrain_name]
total_files = len(pretrain_urls)
print(f"Downloading {total_files} files for {pretrain_name}:")
for index, (key, url) in enumerate(pretrain_urls.items(), 1):
filename = f"{pretrain_name}_{key}.pth"
download_file(url, filename, index, total_files)
else:
print("Pretrain not found.")
else:
print("Failed to fetch pretrains data. Status code:", response.status_code)
except Exception as e:
print("An error occurred while downloading pretrain:", e)
def download_file(url, filename, current_file, total_files):
try:
response = requests.get(url, stream=True)
if response.status_code == 200:
directory = "assets/pretrained_v2"
if not os.path.exists(directory):
os.makedirs(directory)
filepath = os.path.join(directory, "f0"+filename)
with open(filepath, 'wb') as f:
total_length = int(response.headers.get('content-length'))
print(f"Downloading {filename} [{current_file}/{total_files}]")
dl = 0
for data in response.iter_content(chunk_size=4096):
dl += len(data)
f.write(data)
done = int(50 * dl / total_length)
print("\r[%s%s]" % ('=' * done, ' ' * (50 - done)), end='', flush=True)
print(f"\rDownloaded {filename} successfully.")
else:
print(f"Failed to download {filename}. Status code:", response.status_code)
except Exception as e:
print(f"An error occurred while downloading {filename}:", e)
def get_pretrained_models(f0_str):
try:
response = requests.get(PRETRAINS_URL)
if response.status_code == 200:
pretrains_data = json.loads(response.text)
nahidwin = {"32k": f"{f0_str}G32k.pth", "40k": f"{f0_str}G40k.pth", "48k": f"{f0_str}G48k.pth",}
for i in list(pretrains_data.keys()):
ihatemyselfyuh = pretrains_data[i]['G']
nahidwin[i] = f0_str+ihatemyselfyuh.split('/')[-1]
return nahidwin
except:
# fallback lol
return {
"32k": f"{f0_str}G32k.pth",
"40k": f"{f0_str}G40k.pth",
"48k": f"{f0_str}G48k.pth"
}
|