* One liner setup for unsloth studio * Fix install scripts: system deps, activation bugs, curl/wget support - install.sh: detect platform (macOS/Linux/WSL) and check for missing system dependencies (cmake, git, build-essential, libcurl4-openssl-dev). Prompt user once for permission to install all missing packages via brew (macOS) or sudo apt-get (Linux/WSL). Add wget fallback via download() helper since curl is not always present on minimal Linux installs. Fix nested curl|sh stdin stealing by downloading uv installer to a tempfile first. Replace venv activation (no-op in a pipe subshell) with explicit --python flag for uv pip install and direct venv binary invocation. Add idempotency guard for venv creation. Redirect stdin on unsloth studio setup to prevent pipe consumption. On macOS, check for Xcode Command Line Tools and trigger install if missing. - install.ps1: wrap script body in Install-UnslothStudio function so that errors use return instead of exit (exit kills the terminal when run via irm|iex). Remove activate.ps1 invocation entirely -- use explicit --python path for uv pip install and & $UnslothExe for studio setup. This avoids both the child-scope activation bug (& vs dot-source) and the execution policy error on default Windows systems. Add winget availability check with clear error message. Fix PATH refresh to append registry paths instead of replacing the session PATH. Add uv installer fallback via astral.sh PowerShell script if winget install does not put uv on PATH. Broaden Python version check to accept 3.11-3.13. Add idempotency guard for venv creation. - README.md: add wget one-liner alternative for systems without curl. * Fix Tailwind CSS v4 .gitignore bug on Windows (#4444) - Add .gitignore hiding workaround to setup.ps1 (matching existing setup.sh logic) so venv .gitignore files containing "*" don't prevent Tailwind's oxide scanner from finding .tsx source files - Add CSS size validation to setup.sh, setup.ps1, and build.sh to catch truncated Tailwind builds early - Remove stray force-rebuild overrides that made the "skip build if current" cache check dead code in both setup scripts - Add rm -rf dist to build.sh to force clean rebuilds for wheel packaging * Change default port 8000 to 8888, fix installer bugs, improve UX - Change default Studio port from 8000 to 8888 across all entry points (run.py, studio.py, ui.py, colab.py, vite.config.ts, setup scripts) - Update launch banner: "Launching with studio venv..." to "Launching Unsloth Studio... Please wait..." - Add "Open your web browser" banner and rename labels (Local -> Local Access, External -> Worldwide Web Address) - Fix venv idempotency: check for bin/python instead of just directory existence, clean up partial venvs on retry - Fix build.sh CSS validation: handle empty CSS case that silently bypassed the check with "integer expression expected" - Fix install.sh sudo handling: try apt-get without sudo first (works when root), then escalate with per-package tracking and user prompt - Fix install.ps1: check exit code from studio setup, fail on error - Add pciutils to WSL GGUF build dependencies - Apply same smart apt-get escalation pattern to studio/setup.sh * Use detected Python version for venv, abort on non-apt Linux - install.ps1: detect existing Python 3.11/3.12/3.13 and use that version for venv creation instead of always forcing 3.13 - install.sh: exit with error on non-apt Linux distros when required packages cannot be auto-installed, instead of silently continuing * Make sudo permission prompt more prominent with warning banner * Add Accept [Y/n] sudo prompt to studio/setup.sh for consistency * Fix native command exit code handling and sudo decline flow install.ps1: Add $LASTEXITCODE checks after winget (Python), uv venv, and uv pip install calls. $ErrorActionPreference only catches PowerShell cmdlet errors, not native executable failures. The Python check also handles winget returning non-zero for "already installed". setup.sh: Skip llama-server build when user declines sudo or sudo is unavailable. Previously the script continued to section 8 which would fail with confusing errors (e.g. "gcc: command not found") since build-essential was never installed. * Move rm -rf llama.cpp inside build branch to preserve existing install When _SKIP_GGUF_BUILD is set (user declined sudo or sudo unavailable), the previous rm -rf would destroy an already-working llama-server before the skip check ran. Move it inside the else branch so existing builds are preserved when the rebuild is skipped. --------- Co-authored-by: Daniel Han <danielhanchen@users.noreply.github.com> Co-authored-by: Daniel Han <danielhanchen@gmail.com>
133 lines
4.3 KiB
Python
133 lines
4.3 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
|
|
|
|
"""
|
|
Colab-specific helpers for running Unsloth Studio.
|
|
Uses Colab's built-in proxy - no external tunneling needed!
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
|
|
def _bootstrap_studio_venv() -> None:
|
|
"""Expose the Studio venv's site-packages to the current interpreter.
|
|
|
|
On Colab, notebook cells run outside the venv subshell. Instead of
|
|
installing the full stack into system Python, we prepend the venv's
|
|
site-packages so that packages like structlog, fastapi, etc. are
|
|
importable from notebook cells and take priority over system copies.
|
|
"""
|
|
venv_lib = Path.home() / ".unsloth" / "studio" / ".venv" / "lib"
|
|
if not venv_lib.exists():
|
|
import warnings
|
|
|
|
warnings.warn(
|
|
f"Studio venv not found at {venv_lib.parent} -- run 'unsloth studio setup' first",
|
|
stacklevel = 2,
|
|
)
|
|
return
|
|
for sp in venv_lib.glob("python*/site-packages"):
|
|
sp_str = str(sp)
|
|
if sp_str not in sys.path:
|
|
sys.path.insert(0, sp_str)
|
|
|
|
|
|
_bootstrap_studio_venv()
|
|
|
|
# Add backend to path early so local modules like loggers can be imported
|
|
backend_path = str(Path(__file__).parent)
|
|
if backend_path not in sys.path:
|
|
sys.path.insert(0, backend_path)
|
|
|
|
from loggers import get_logger
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
def get_colab_url(port: int = 8888) -> str:
|
|
"""
|
|
Get the actual Colab proxy URL for a port.
|
|
"""
|
|
try:
|
|
from google.colab.output import eval_js
|
|
|
|
# Use Colab's proxy mechanism
|
|
url = eval_js(f"google.colab.kernel.proxyPort({port})", timeout_sec = 5)
|
|
return url if url else f"http://localhost:{port}"
|
|
except Exception as e:
|
|
logger.info(f"Note: Could not get Colab URL ({e})")
|
|
return f"http://localhost:{port}"
|
|
|
|
|
|
def show_link(port: int = 8888):
|
|
"""Display a styled clickable link to the UI."""
|
|
from IPython.display import display, HTML
|
|
|
|
# Get real Colab proxy URL
|
|
url = get_colab_url(port)
|
|
|
|
short_url = (
|
|
url[: url.index("-", url.index(f"{port}-") + len(str(port)) + 1) + 1] + "..."
|
|
if f"{port}-" in url
|
|
else url
|
|
)
|
|
html = f"""
|
|
<div style="display: inline-block; padding: 20px; background: #ffffff; border: 2px solid #000000;
|
|
border-radius: 12px; margin: 10px 0; font-family: system-ui, -apple-system, sans-serif;">
|
|
<h2 style="color: #000000; margin: 0 0 12px 0; font-size: 26px; font-weight: 800;
|
|
display: flex; align-items: center; gap: 12px;">
|
|
<img src="https://github.com/unslothai/unsloth/raw/main/studio/frontend/public/unsloth-gem.png"
|
|
height="48" style="display:block;">
|
|
Unsloth Studio is Ready!
|
|
</h2>
|
|
<a href="{url}" target="_blank"
|
|
style="display: inline-flex; align-items: center; gap: 10px; padding: 14px 28px;
|
|
background: #000000; color: white; text-decoration: none; border-radius: 8px;
|
|
font-weight: 800; font-size: 16px;">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="white"><polygon points="5,3 19,12 5,21"/></svg>
|
|
Open Unsloth Studio
|
|
</a>
|
|
<p style="color: #333333; margin: 16px 0 0 0; font-size: 13px; font-family: monospace;">
|
|
{short_url}
|
|
</p>
|
|
</div>
|
|
"""
|
|
display(HTML(html))
|
|
|
|
|
|
def start(port: int = 8888):
|
|
"""
|
|
Start Unsloth Studio server in Colab and display the URL.
|
|
|
|
Usage:
|
|
from colab import start
|
|
start()
|
|
"""
|
|
import sys
|
|
|
|
logger.info("🦥 Starting Unsloth Studio...")
|
|
|
|
logger.info(" Loading backend...")
|
|
from run import run_server
|
|
|
|
# Auto-detect frontend path
|
|
repo_root = Path(__file__).parent.parent
|
|
frontend_path = repo_root / "frontend" / "dist"
|
|
|
|
if not frontend_path.exists():
|
|
logger.info("❌ Frontend not built! Please run the setup cell first.")
|
|
return
|
|
|
|
logger.info(" Starting server...")
|
|
# Start server silently
|
|
run_server(host = "0.0.0.0", port = port, frontend_path = frontend_path, silent = True)
|
|
|
|
logger.info(" Server started!")
|
|
|
|
# Show the clickable link with real URL
|
|
show_link(port)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
start()
|