File size: 8,562 Bytes
209132b |
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
{
"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
} |