2026-10-21

Launching Fooocus on Google Colab on October, 2026

 Thats crazy how fast everything evolves and develops. I used to play with Fooocus - image generation locally - but not really locally - using google colab cloud computing platform. So the problem is that due to that rapid development Fooocus natively is ... well, kind of is not supported? At least with the commands which still exist in Fooocus github page. 

I dived into how to solve this and with a bit of discussion with Google Gemini I got a running Fooocus with this:


# ----------------------------------------------------------
import os
import subprocess
from pathlib import Path

# ==========================================================
# FOOOCUS 2.5.5 - GOOGLE COLAB T4 INSTALLER
# Python 3.10 | Gradio 3.41.2 | Compatible dependencies
# ==========================================================

os.chdir("/content")
os.environ.pop("PYTHONPATH", None)
os.environ["MPLBACKEND"] = "agg"

CONDA = "/content/miniconda/bin/conda"
PY = "/content/miniconda/envs/fooocus/bin/python"
REPO = "/content/Fooocus"

def run(*args, cwd=None):
subprocess.run(list(args), cwd=cwd, check=True)

# ----------------------------------------------------------
# 1. Install Miniconda (only if missing)
# ----------------------------------------------------------
if not Path(CONDA).exists():
print("Installing Miniconda...")
installer = "/content/miniconda.sh"
run(
"wget", "-q", "-O", installer,
"https://repo.anaconda.com/miniconda/"
"Miniconda3-latest-Linux-x86_64.sh"
)
run("bash", installer, "-b", "-p", "/content/miniconda")

# ----------------------------------------------------------
# 2. Accept Conda Terms of Service
# ----------------------------------------------------------
for channel in [
"https://repo.anaconda.com/pkgs/main",
"https://repo.anaconda.com/pkgs/r"
]:
run(CONDA, "tos", "accept",
"--override-channels", "--channel", channel)

# ----------------------------------------------------------
# 3. Create Python 3.10 environment
# ----------------------------------------------------------
if not Path(PY).exists():
print("Creating Python 3.10 environment...")
run(CONDA, "create", "-n", "fooocus",
"python=3.10", "-y")

# ----------------------------------------------------------
# 4. Clone Fooocus
# ----------------------------------------------------------
if not Path(REPO).exists():
print("Cloning Fooocus...")
run("git", "clone",
"https://github.com/lllyasviel/Fooocus.git",
REPO)

# ----------------------------------------------------------
# 5. Install Fooocus requirements
# ----------------------------------------------------------
print("Installing Fooocus dependencies...")

requirements = Path(REPO) / "requirements_versions.txt"

if not requirements.exists():
raise FileNotFoundError(requirements)

run(PY, "-m", "pip", "install",
"-r", str(requirements))

# ----------------------------------------------------------
# 6. Apply verified compatibility fixes
# ----------------------------------------------------------
print("Applying compatible UI dependencies...")

run(
PY, "-m", "pip", "install", "--force-reinstall",
"pydantic==1.10.15",
"fastapi==0.103.1",
"starlette==0.27.0",
"gradio==3.41.2",
"jinja2==3.1.2",
"markupsafe==2.1.5",
"pyyaml==6.0.1"
)

# ----------------------------------------------------------
# 7. Display installed versions
# ----------------------------------------------------------
print("\nChecking installed versions...")

run(PY, "-c", """
import gradio, fastapi, starlette, pydantic, jinja2, yaml
for name, mod in [
("Gradio", gradio),
("FastAPI", fastapi),
("Starlette", starlette),
("Pydantic", pydantic),
("Jinja2", jinja2),
("PyYAML", yaml)
]:
print(f"{name}: {mod.__version__}")
""")

# ----------------------------------------------------------
# 8. Launch Fooocus
# ----------------------------------------------------------
print("\nLaunching Fooocus...")
print("GPU: Tesla T4 (if selected in Colab)")
print("VRAM mode: Automatic")
print("Public Gradio sharing: Enabled")

os.chdir(REPO)

run(PY, "launch.py", "--share", cwd=REPO)

# ----------------------------------------------------------

I hope that it will be useful to someone. Maybe for ... a few days in this very rapid time?

Nav komentāru:

Ierakstīt komentāru