Download kaggle_start.py from Nokia123543/muscriptor-large-fork: direct link, hf CLI and curl.
- Browser
- Download file 2.81 kB
-
https://huggingface.co/Nokia123543/muscriptor-large-fork/resolve/main/kaggle_start.py
- Command line
-
hf download hf://Nokia123543/muscriptor-large-fork/kaggle_start.py
-
curl -L -o kaggle_start.py https://huggingface.co/Nokia123543/muscriptor-large-fork/resolve/main/kaggle_start.py
2.81 kB
| """Kaggle без карты и без Colab: одна ячейка поднимает MuScriptor на GPU с туннелем. | |
| Вставь в ячейку: | |
| %run kaggle_start.py | |
| или | |
| !python3 kaggle_start.py | |
| """ | |
| import os | |
| import shutil | |
| import subprocess | |
| import sys | |
| PACKAGE = "muscriptor==0.4.0" | |
| PLUS_ZIP = ("https://huggingface.co/Nokia123543/muscriptor-large-fork" | |
| "/resolve/main/plus.zip") | |
| def shell(command: str) -> int: | |
| print("$ " + command[:110]) | |
| return subprocess.call(command, shell=True) | |
| def supported_flags() -> set[str]: | |
| """Узнать, какие флаги понимает установленный diag.py.""" | |
| try: | |
| output = subprocess.run([sys.executable, "plus/diag.py", "--help"], | |
| capture_output=True, text=True, timeout=60).stdout | |
| except Exception: | |
| return set() | |
| return set(name for name in output.split() if name.startswith("--")) | |
| def keep_known(command: list[str], known: set[str]) -> list[str]: | |
| """Выкинуть флаги, которых нет в этой версии diag (старый архив).""" | |
| kept, skipped, index = [], [], 0 | |
| while index < len(command): | |
| item = command[index] | |
| if item.startswith("--") and known and item not in known: | |
| skipped.append(item) | |
| index += 1 | |
| if index < len(command) and not command[index].startswith("--"): | |
| index += 1 | |
| continue | |
| kept.append(item) | |
| index += 1 | |
| if skipped: | |
| print("старый plus.zip: пропускаю неподдерживаемые флаги %s" % ", ".join(skipped)) | |
| return kept | |
| def main() -> int: | |
| if not shutil.which("fluidsynth"): | |
| shell("apt-get -qq update && apt-get -qq install -y fluidsynth unzip >/dev/null 2>&1") | |
| try: | |
| import muscriptor # noqa: F401 | |
| except ImportError: | |
| shell("%s -m pip -q install '%s'" % (sys.executable, PACKAGE)) | |
| shell('rm -f plus.zip && wget -q -O plus.zip "%s?v=$(date +%%s)" && unzip -oq plus.zip' | |
| % PLUS_ZIP) | |
| if not os.path.exists("plus/diag.py"): | |
| print("plus.zip не распаковался: проверь интернет в ячейке") | |
| return 1 | |
| # GPU плюс float16 экономит память, туннель даёт постоянное имя nokia1709 | |
| command = [sys.executable, "plus/diag.py", "--start", | |
| "--start-device", "cuda", "--start-dtype", "float16", | |
| "--start-tunnel", os.environ.get("MUSCRIPTOR_TUNNEL", "serveo"), | |
| "--stay"] | |
| command = keep_known(command, supported_flags()) | |
| print("запускаю: " + " ".join(command)) | |
| return subprocess.call(command) | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |