Spaces:
Running
on
Zero
Running
on
Zero
File size: 2,220 Bytes
7bc29af |
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 |
import json
import os
import gc
import psutil
import requests
import subprocess
import time
import logging
import sys
import shutil
now_dir = os.getcwd()
sys.path.append(now_dir)
first_cell_executed = False
file_folder = "Colab-for-MDX_B"
def first_cell_ran():
global first_cell_executed
if first_cell_executed:
#print("The 'first_cell_ran' function has already been executed.")
return
first_cell_executed = True
os.makedirs("tmp_models", exist_ok=True)
class hide_opt: # hide outputs
def __enter__(self):
self._original_stdout = sys.stdout
sys.stdout = open(os.devnull, "w")
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout.close()
sys.stdout = self._original_stdout
def get_size(bytes, suffix="B"): # read ram
global svmem
factor = 1024
for unit in ["", "K", "M", "G", "T", "P"]:
if bytes < factor:
return f"{bytes:.2f}{unit}{suffix}"
bytes /= factor
svmem = psutil.virtual_memory()
def use_uvr_without_saving():
print("Notice: files won't be saved to personal drive.")
print(f"Downloading {file_folder}...", end=" ")
with hide_opt():
#os.chdir(mounting_path)
items_to_move = ["demucs", "diffq","julius","model","separated","tracks","mdx.py","MDX-Net_Colab.ipynb"]
subprocess.run(["git", "clone", "https://github.com/NaJeongMo/Colab-for-MDX_B.git"])
for item_name in items_to_move:
item_path = os.path.join(file_folder, item_name)
if os.path.exists(item_path):
if os.path.isfile(item_path):
shutil.move(item_path, now_dir)
elif os.path.isdir(item_path):
shutil.move(item_path, now_dir)
try:
shutil.rmtree(file_folder)
except PermissionError:
print(f"No se pudo eliminar la carpeta {file_folder}. Puede estar relacionada con Git.")
use_uvr_without_saving()
print("done!")
if not os.path.exists("tracks"):
os.mkdir("tracks")
first_cell_ran() |