{ "cells": [ { "cell_type": "code", "source": [ "from IPython.display import clear_output\n", "!git clone https://github.com/Ysb321/ImgGen\n", "!pip install -r /content/ImgGen/requirements.txt\n", "clear_output()\n" ], "metadata": { "id": "p6WhlbJGlcKP" }, "execution_count": 1, "outputs": [] }, { "cell_type": "code", "source": [ "# @title Default Model (Important to run)\n", "import os\n", "import requests\n", "\n", "def download_civitai_model(bearer_token, download_url, save_path):\n", " \"\"\"\n", " Downloads a model from Civitai using a bearer token.\n", "\n", " Args:\n", " bearer_token: Your Civitai bearer token.\n", " download_url: The URL of the model to download.\n", " save_path: The full path to save the downloaded file.\n", " \"\"\"\n", " headers = {\"Authorization\": f\"Bearer {bearer_token}\"}\n", " response = requests.get(download_url, headers=headers, stream=True)\n", "\n", " if response.status_code == 200:\n", " os.makedirs(os.path.dirname(save_path), exist_ok=True) # Create directories if they don't exist\n", " with open(save_path, \"wb\") as f:\n", " for chunk in response.iter_content(chunk_size=1024):\n", " if chunk:\n", " f.write(chunk)\n", " print(f\"File downloaded successfully to: {save_path}\")\n", " else:\n", " print(f\"Download failed with status code: {response.status_code}\")\n", "\n", "# Example usage:\n", "bearer_token = \"6748e0f8e6085cd9349551385ce8943a\"\n", "download_url = \"https://civitai.com/api/download/models/909781?type=Model&format=SafeTensor&size=full&fp=fp16\"\n", "save_path = \"/content/models/default.safetensors\"\n", "\n", "download_civitai_model(bearer_token, download_url, save_path)" ], "metadata": { "id": "NXQ7VYCFjux3", "cellView": "form" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "# @title Model Download\n", "import os\n", "import requests\n", "\n", "def download_civitai_model(bearer_token, download_url, save_path):\n", " \"\"\"\n", " Downloads a model from Civitai using a bearer token.\n", "\n", " Args:\n", " bearer_token: Your Civitai bearer token.\n", " download_url: The URL of the model to download.\n", " save_path: The full path to save the downloaded file.\n", " \"\"\"\n", " headers = {\"Authorization\": f\"Bearer {bearer_token}\"}\n", " response = requests.get(download_url, headers=headers, stream=True)\n", "\n", " if response.status_code == 200:\n", " os.makedirs(os.path.dirname(save_path), exist_ok=True) # Create directories if they don't exist\n", " with open(save_path, \"wb\") as f:\n", " for chunk in response.iter_content(chunk_size=1024):\n", " if chunk:\n", " f.write(chunk)\n", " print(f\"File downloaded successfully to: {save_path}\")\n", " else:\n", " print(f\"Download failed with status code: {response.status_code}\")\n", "\n", "# Example usage:\n", "bearer_token = \"6748e0f8e6085cd9349551385ce8943a\"\n", "download_url = \"https://civitai.com/api/download/models/555687?type=Model&format=SafeTensor&size=pruned&fp=fp16\" # @param {type: \"string\"}\n", "model_name = \"paintjob\" # @param {type: \"string\"}\n", "save_path = f\"/content/models/{model_name}.safetensors\"\n", "\n", "download_civitai_model(bearer_token, download_url, save_path)" ], "metadata": { "cellView": "form", "id": "1jP2wKeeksGo" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "# @title Lora Download\n", "\n", "import os\n", "import requests\n", "\n", "def download_civitai_model(bearer_token, download_url, save_path):\n", " \"\"\"\n", " Downloads a model from Civitai using a bearer token.\n", "\n", " Args:\n", " bearer_token: Your Civitai bearer token.\n", " download_url: The URL of the model to download.\n", " save_path: The full path to save the downloaded file.\n", " \"\"\"\n", " headers = {\"Authorization\": f\"Bearer {bearer_token}\"}\n", " response = requests.get(download_url, headers=headers, stream=True)\n", "\n", " if response.status_code == 200:\n", " os.makedirs(os.path.dirname(save_path), exist_ok=True) # Create directories if they don't exist\n", " with open(save_path, \"wb\") as f:\n", " for chunk in response.iter_content(chunk_size=1024):\n", " if chunk:\n", " f.write(chunk)\n", " print(f\"File downloaded successfully to: {save_path}\")\n", " else:\n", " print(f\"Download failed with status code: {response.status_code}\")\n", "\n", "# Example usage:\n", "bearer_token = \"6748e0f8e6085cd9349551385ce8943a\"\n", "download_url = \"https://civitai.com/api/download/models/378950?type=Model&format=SafeTensor\" # @param {type: \"string\"}\n", "model_name = \"styles\" # @param {type: \"string\"}\n", "save_path = f\"/content/lora/{model_name}.safetensors\"\n", "\n", "download_civitai_model(bearer_token, download_url, save_path)" ], "metadata": { "cellView": "form", "id": "7vHNtfWSpbKN" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "#@title Run\n", "!python /content/ImgGen/main.py" ], "metadata": { "id": "_E4CYZfAmqrw", "cellView": "form" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "# @title Zip file Creater\n", "import os\n", "import zipfile\n", "from google.colab import files\n", "\n", "def zip_folder(folder_path, output_zip_path):\n", " \"\"\"Zips the contents of a folder into a zip file.\n", "\n", " Args:\n", " folder_path: The path to the folder to be zipped.\n", " output_zip_path: The path to the output zip file.\n", " \"\"\"\n", " # Use zipfile for creating zip files\n", " with zipfile.ZipFile(output_zip_path, 'w') as zip_file:\n", " for root, _, files in os.walk(folder_path):\n", " for file in files:\n", " file_path = os.path.join(root, file)\n", " zip_file.write(file_path, os.path.relpath(file_path, folder_path))\n", "\n", "# Replace with the actual path to your folder\n", "folder_to_zip = \"/content/images\"\n", "output_zip_file = \"/content/images.zip\"\n", "\n", "zip_folder(folder_to_zip, output_zip_file)" ], "metadata": { "id": "Sjx_A0TNyeAS", "cellView": "form" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "!curl -L -H \"Content-Type: application/json\" -H \"Authorization: Bearer 6748e0f8e6085cd9349551385ce8943a\" -o /content/ImgGen/model_link.safetensors https://civitai.com/api/download/models/909781?type=Model&format=SafeTensor&size=full&fp=fp16" ], "metadata": { "id": "aIa50T3Wz-kj" }, "execution_count": null, "outputs": [] } ], "metadata": { "accelerator": "GPU", "colab": { "gpuType": "T4", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }