Skip to content

Commit

Permalink
the actual code stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomGamingDev committed Oct 1, 2023
0 parents commit 98f0441
Show file tree
Hide file tree
Showing 12 changed files with 972 additions and 0 deletions.
123 changes: 123 additions & 0 deletions MCSkinGen.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"private_outputs": true,
"provenance": [],
"gpuType": "T4",
"toc_visible": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"source": [
"In this block of code it will ask for your token from Hugging Face.\n",
"\n",
"If you don't have an account you can make one here: https://huggingface.co/join\n",
"\n",
"Before you can do this you need to accept the license agreement for the model, which you can do here: https://huggingface.co/CompVis/stable-diffusion-v1-4\n",
"\n",
"On the token page select \"new token\" and ask for a \"read\" token (you can name it \"Colab\")."
],
"metadata": {
"id": "8pkEI3oVt_QD"
}
},
{
"cell_type": "code",
"source": [
"!pip install --quiet --upgrade diffusers transformers scipy mediapy accelerate networks lora utils pillow\n",
"!git clone https://github.com/RandomGamingDev/MCSkinsGen\n",
"!huggingface-cli login"
],
"metadata": {
"id": "GR4vF2bw-sHR"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from diffusers import PNDMScheduler, DDIMScheduler, LMSDiscreteScheduler\n",
"import mediapy as media\n",
"import torch\n",
"from torch import autocast\n",
"from diffusers import StableDiffusionPipeline\n",
"from safetensors.torch import load_file\n",
"\n",
"scheduler = PNDMScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule=\"scaled_linear\", skip_prk_steps=True)\n",
"\n",
"#@markdown Stable Diffusion Model\n",
"model_id = \"runwayml/stable-diffusion-v1-5\" #@param {type:\"string\"}\n",
"#@markdown The Device (this is mostly just for if you're running it on a different machine)\n",
"device = \"cuda\" #@param {type:\"string\"}\n",
"\n",
"pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16, revision=\"fp16\", safety_checker=None, use_auth_token=True)\n",
"pipe = pipe.to(device)\n",
"\n",
"#@markdown LoRA Model\n",
"lora_model = \"mcskins-18.safetensors\" #@param {type:\"string\"}\n",
"\n",
"pipe.load_lora_weights(f\"/MCSkinsGen/models/{ lora_model }\")\n"
],
"metadata": {
"id": "bG2hkmSEvByV"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Here is where you actually make images. Change the \"prompt\" to whatever you want to try and then change \"num_images\" if you want more than one image generated. You can re-run this cell without having to re-run everything before it."
],
"metadata": {
"id": "IoTE794luOXD"
}
},
{
"cell_type": "code",
"source": [
"import PIL\n",
"\n",
"#@markdown Generation Parameters\n",
"prompt = \"A Alchemist minecraft skin in the tv category. Alchemist with golden hair.\" #@param {type:\"string\"}\n",
"num_images = 2 #@param {type:\"number\"}\n",
"\n",
"prompts = [prompt] * num_images\n",
"\n",
"#@markdown AI Parameters\n",
"guidance_scale = 7.5 #@param {type:\"number\"}\n",
"num_inference_steps = 50 #@param {type:\"number\"}\n",
"#@markdown Recommended values: <br/>\n",
"#@markdown Most Recommended: `guidance_scale=7.5, num_inference_steps=50` <br/>\n",
"#@markdown `guidance_scale=15, num_inference_steps=50 or 100 or 200` <br/>\n",
"#@markdown `guidance_scale=30, num_inference_steps=100`\n",
"\n",
"with autocast(\"cuda\"):\n",
" images = pipe(prompts, guidance_scale=7.5, num_inference_steps=50).images\n",
"\n",
"#@markdown To download the skins simply right click and press `Save As`\n",
"images = [image.resize((64, 64), resample=PIL.Image.Resampling.NEAREST) for image in images]\n",
"media.show_images(images)"
],
"metadata": {
"id": "AUc4QJfE-uR9",
"cellView": "form"
},
"execution_count": null,
"outputs": []
}
]
}
Loading

0 comments on commit 98f0441

Please sign in to comment.