{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Run Fooocus" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "VjYy0F2gZIPR" }, "outputs": [], "source": [ "!pip install pygit2==1.12.2\n", "%cd /content\n", "!git clone https://github.com/lllyasviel/Fooocus.git\n", "%cd /content/Fooocus\n", "!python entry_with_update.py --share\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download checkpoints and LoRAs from civitai\n", "to download checkpoints and LoRAs from civitai you have to run Fooocus first\n", "\n", "https://civitai.com/models" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# put the link of the model you want to download (checkpoint or LoRA)\n", "# link can specify a version id and if not specified the latest version will be downloaded\n", "# url example without version id: https://civitai.com/models/133005/juggernaut-xl\n", "# url example with version id: https://civitai.com/models/133005?modelVersionId=252902\n", "\n", "civitai_url = \"https://civitai.com/models/133005/juggernaut-xl\"\n", "\n", "# -----------------------------\n", "import requests\n", "from urllib.parse import urlparse\n", "from urllib.parse import parse_qs\n", "\n", "allowed_types = ['Checkpoint', 'LORA']\n", "save_locations = {\n", " 'Checkpoint': '/content/Fooocus/models/checkpoints',\n", " 'LORA': '/content/Fooocus/models/loras'\n", "}\n", "\n", "parsed_url = urlparse(civitai_url)\n", "\n", "model_id = parsed_url.path.split('/')[parsed_url.path.split('/').index('models') + 1]\n", "model_version_id = parse_qs(parsed_url.query).get('modelVersionId')\n", "\n", "url = \"https://civitai.com/api/v1/models/\" + model_id\n", "response = requests.get(url)\n", "\n", "if response.status_code != 200:\n", " raise RuntimeError('model not found')\n", "\n", "data = response.json()\n", "model_type = data.get('type')\n", "\n", "if model_type not in allowed_types:\n", " raise RuntimeError('model is not a checkpoint or LoRA')\n", "\n", "model_versions = data.get('modelVersions')\n", "\n", "selected_version = None\n", "\n", "if model_version_id:\n", " for model_version in model_versions:\n", " if str(model_version.get('id')) == model_version_id[0]:\n", " selected_version = model_version\n", "else:\n", " selected_version = model_versions[0]\n", "\n", "if selected_version is None:\n", " raise RuntimeError(\"this version doesn't exist\")\n", "\n", "\n", "files = selected_version.get('files')\n", "primary_file = None\n", "\n", "for f in files:\n", " if f.get('primary'):\n", " primary_file = f\n", "\n", "download_url = primary_file.get('downloadUrl')\n", "file_name = primary_file.get('name')\n", "\n", "LOCATION = save_locations[model_type]\n", "%cd $LOCATION\n", "\n", "model_name = data.get('name')\n", "selected_version_name = selected_version.get('name')\n", "print(f'downloading {model_name} ({model_type} version {selected_version_name})')\n", "\n", "get_ipython().system(f'wget -O \"{file_name}\" \"{download_url}\"')" ] } ], "metadata": { "accelerator": "GPU", "colab": { "gpuType": "T4", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }