File size: 4,546 Bytes
75d0a89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
╔══════════════════════════════════════════════════════════════╗
β•‘ Author: p3nGu1nZz                                            β•‘
β•‘ Email: rawsonkara@gmail.com                                  β•‘
β•‘ Copyright (c) 2025 Huggingface                               β•‘
β•‘ License: MIT                                                 β•‘
β•‘ This source file is subject to the terms and conditions      β•‘
β•‘ defined in the file 'LICENSE', which is part of this sorcery β•‘
β•‘ code package.                                                β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
"""

DONUT = """
    β €β €β €β €β €β €β €β’€β£€β£€β£€β£€β£€β£€β£€β €β €β €β €β €β €
    ⠀⠀⠀⒀⑀⠖⠛⠛⠉⒉⠉⠉⠙⠛⠛⠻⠷⣦⑀⠀⠀
    β €β €β£°β ‰β €β €β –β‘„β €β ˜β €β’ β‘°β €β €β €β£¨β‘β’¦β €
    β €β’€β£―β ―β ƒβ €β €β €β’β£€β£€β£€β£„β‘€β ˆβ €β €β €β ˆβ‘‡
    β €β‘œβ β €β €β‘€β €β‘΄β ›β ‰β ™β Ίβ‘»β£¦β €β €β ²β †β €β’Ή
    β’€β‘·β‘¦β €β ˜β ƒβ’Έβ β €β €β €β €β£»β£Ώβ €β €β €β €β£Ώ
    β ˜β Ώβ β €β €β €β ˆβ’†β €β €β €β’€β£΄β£Ώβ β’Άβ €β –β’ β‘
    ⠀⒗⒒⣀⣄⠀⠀⠀⠉⠙⠛⠛⒩⑄⠀⠀⠀⠀⑾⠁
    β €β ˆβ’§β£Έβ ±β †β €β €β β €β €β €β €β’€β‘ β’€β €β£ β žβ β €
    ⠀⠀⠀⠉⠻⒬⑩⑉⒭⑑⑂⒐β£ͺβ£΅β£²β‘Ύβ žβ ‹β €β €β €
    β €β €β €β €β €β €β ˆβ ‰β ‰β β ‰β ‰β ‰β ‰β β €β €β €β €β €β €β €β €β €
"""

CONFIG = {
    "url": "https://download.pytorch.org/whl/cu124",
    "cmds": [
        "python -m pip install --upgrade pip",
        "python -m pip install --upgrade setuptools",
        "python -m pip install --upgrade wheel"
    ],
    "pkg_common": ["tqdm==4.62.3", "pillow==8.4.0"],
    "pkg_cuda"  : ["torch==2.5.1+cu124 --index-url https://download.pytorch.org/whl/cu124"],
    "pkg_cpu"   : ["torch==2.5.1"],
    "pkg_indiv" : ["matplotlib", "numpy==2.1.3"]
}

import subprocess as sp
import sys
import importlib.metadata as imd

def ensure_rich():
    """
    Ensure the rich library is installed.
    """
    try:
        imd.version("rich")
    except imd.PackageNotFoundError:
        sp.check_call([sys.executable, "-m", "pip", "install", "rich"])

# Ensure rich is installed before importing
ensure_rich()

from rich.console import Console
from rich.text import Text

console = Console()

def run_cmd(cmd):
    """
    Execute a shell command.
    """
    try:
        sp.check_call(cmd, shell=True)
    except sp.CalledProcessError as err:
        console.print(f"[red]Error running command: {cmd}\n{err}[/red]")

def install_pkg(pkg):
    """
    Install a package using pip.
    """
    try:
        sp.check_call([sys.executable, "-m", "pip", "install", pkg])
    except sp.CalledProcessError as err:
        console.print(f"[red]Error installing package: {pkg}\n{err}[/red]")

def is_installed(pkg):
    """
    Check if a package is installed.
    """
    try:
        imd.version(pkg)
        return True
    except imd.PackageNotFoundError:
        return False

def display_donut():
    """
    Display the ASCII donut art.
    """
    donut_text = Text(DONUT, style="bold magenta")
    console.print(donut_text)

def upgrade_tools():
    """
    Upgrade pip, setuptools, and wheel.
    """
    for cmd in CONFIG["cmds"]:
        run_cmd(cmd)

def install_packages(packages):
    """
    Install a list of packages if not already installed.
    """
    for pkg in packages:
        if not is_installed(pkg.split("==")[0]):
            install_pkg(pkg)

def ensure_numpy():
    """
    Ensure numpy is compatible.
    """
    try:
        np_ver = imd.version("numpy")
        if not np_ver.startswith("2.1.3"):
            install_pkg("numpy==2.1.3")
    except imd.PackageNotFoundError:
        install_pkg("numpy==2.1.3")

def main():
    """
    Main function to orchestrate the setup.
    """
    display_donut()
    upgrade_tools()
    ensure_numpy()
    install_pkg("matplotlib")
    install_packages(CONFIG["pkg_common"])
    try:
        import torch
        if torch.cuda.is_available():
            install_packages(CONFIG["pkg_cuda"])
        else:
            install_packages(CONFIG["pkg_cpu"])
    except ImportError:
        install_packages(CONFIG["pkg_cpu"])

    console.print("[bold green]All Your Donut Belong To Us![/bold green]\n")

if __name__ == "__main__":
    main()