3d model output added
Browse files- 3d_model_player.glb +0 -0
- 64x32to64x64skin3dmodel.sh +14 -0
- app.py +73 -5
- packages.txt +1 -0
- requirements.txt +3 -1
3d_model_player.glb
ADDED
|
Binary file (61.5 kB). View file
|
|
|
64x32to64x64skin3dmodel.sh
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
convert "$1" -background transparent -extent 64x64 \
|
| 2 |
+
\( "$1" -crop 4x4+4+16 -flop \) -geometry +20+48 -composite \
|
| 3 |
+
\( "$1" -crop 4x4+8+16 -flop \) -geometry +24+48 -composite \
|
| 4 |
+
\( "$1" -crop 4x12+8+20 -flop \) -geometry +16+52 -composite \
|
| 5 |
+
\( "$1" -crop 4x12+4+20 -flop \) -geometry +20+52 -composite \
|
| 6 |
+
\( "$1" -crop 4x12+0+20 -flop \) -geometry +24+52 -composite \
|
| 7 |
+
\( "$1" -crop 4x12+12+20 -flop \) -geometry +28+52 -composite \
|
| 8 |
+
\( "$1" -crop 4x4+44+16 -flop \) -geometry +36+48 -composite \
|
| 9 |
+
\( "$1" -crop 4x4+48+16 -flop \) -geometry +40+48 -composite \
|
| 10 |
+
\( "$1" -crop 4x12+48+20 -flop \) -geometry +32+52 -composite \
|
| 11 |
+
\( "$1" -crop 4x12+44+20 -flop \) -geometry +36+52 -composite \
|
| 12 |
+
\( "$1" -crop 4x12+40+20 -flop \) -geometry +40+52 -composite \
|
| 13 |
+
\( "$1" -crop 4x12+52+20 -flop \) -geometry +44+52 -composite \
|
| 14 |
+
"$1-converted.png"
|
app.py
CHANGED
|
@@ -2,8 +2,12 @@ import subprocess
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
|
|
|
|
|
|
|
|
|
| 5 |
import spaces
|
| 6 |
|
|
|
|
| 7 |
if torch.cuda.is_available():
|
| 8 |
device = "cuda"
|
| 9 |
print("Using GPU")
|
|
@@ -13,21 +17,82 @@ else:
|
|
| 13 |
|
| 14 |
|
| 15 |
subprocess.run(["git", "clone", "https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator.git"])
|
| 16 |
-
|
| 17 |
|
| 18 |
@spaces.GPU()
|
| 19 |
def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, output_image_name, verbose):
|
|
|
|
|
|
|
|
|
|
| 20 |
if stable_diffusion_model == '2':
|
| 21 |
sd_model = "minecraft-skins"
|
| 22 |
else:
|
| 23 |
sd_model = "minecraft-skins-sdxl"
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
os.system(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Define Gradio UI components
|
| 33 |
prompt = gr.Textbox(label="Your Prompt", info="What the Minecraft Skin should look like")
|
|
@@ -53,7 +118,10 @@ gr.Interface(
|
|
| 53 |
output_image_name,
|
| 54 |
verbose
|
| 55 |
],
|
| 56 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 57 |
title="Minecraft Skin Generator",
|
| 58 |
description="Make AI generated Minecraft Skins by a Finetuned Stable Diffusion Version!<br>Model used: https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator<br>Hugging Face Space made by [Nick088](https://linktr.ee/Nick088)",
|
| 59 |
).launch(show_api=False, share=True)
|
|
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
| 5 |
+
from PIL import Image, ImageEnhance
|
| 6 |
+
from pygltflib import GLTF2
|
| 7 |
+
from pygltflib.utils import ImageFormat, Texture, Material, Image as GLTFImage
|
| 8 |
import spaces
|
| 9 |
|
| 10 |
+
|
| 11 |
if torch.cuda.is_available():
|
| 12 |
device = "cuda"
|
| 13 |
print("Using GPU")
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
subprocess.run(["git", "clone", "https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator.git"])
|
| 20 |
+
|
| 21 |
|
| 22 |
@spaces.GPU()
|
| 23 |
def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, output_image_name, verbose):
|
| 24 |
+
|
| 25 |
+
os.chdir("Stable_Diffusion_Finetuned_Minecraft_Skin_Generator")
|
| 26 |
+
|
| 27 |
if stable_diffusion_model == '2':
|
| 28 |
sd_model = "minecraft-skins"
|
| 29 |
else:
|
| 30 |
sd_model = "minecraft-skins-sdxl"
|
| 31 |
|
| 32 |
+
inference_command = f"python Python_Scripts/{sd_model}.py '{prompt}' {num_inference_steps} {guidance_scale} {model_precision_type} {seed} {output_image_name} {'--verbose' if verbose else ''}"
|
| 33 |
+
|
| 34 |
+
os.system(inference_command)
|
| 35 |
+
|
| 36 |
+
os.chdir("..")
|
| 37 |
+
|
| 38 |
+
to3d_model_command = f"sh 64x32to64x64skin3dmodel.sh Stable_Diffusion_Finetuned_Minecraft_Skin_Generator/output_minecraft_skins/{output_image_name}"
|
| 39 |
|
| 40 |
+
os.system(to3d_model_command)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
filename = "3d_model_player.glb"
|
| 44 |
+
gltf = GLTF2().load(filename)
|
| 45 |
+
|
| 46 |
+
# Step 1: Find the index of the existing texture you want to replace
|
| 47 |
+
# Let's assume the texture you want to replace is at index 1 (you need to replace 1 with the actual index)
|
| 48 |
+
existing_texture_index = 0
|
| 49 |
+
|
| 50 |
+
# Check if the existing_texture_index is valid
|
| 51 |
+
if existing_texture_index < len(gltf.textures):
|
| 52 |
+
# Step 2: Remove the old texture and its associated image from the GLB
|
| 53 |
+
# Remove the texture
|
| 54 |
+
gltf.textures.pop(existing_texture_index)
|
| 55 |
+
|
| 56 |
+
# Remove the image associated with the texture
|
| 57 |
+
existing_image_index = gltf.materials[0].pbrMetallicRoughness.baseColorTexture.index
|
| 58 |
+
gltf.images.pop(existing_image_index)
|
| 59 |
+
|
| 60 |
|
| 61 |
+
# Step 3: Add the new image and texture to the GLB
|
| 62 |
+
# Create and add a new image to the glTF (same as before)
|
| 63 |
+
new_image = GLTFImage()
|
| 64 |
+
new_image.uri = os.path.join(f"Stable_Diffusion_Finetuned_Minecraft_Skin_Generator/output_minecraft_skins/{output_image_name}-converted.png")
|
| 65 |
+
gltf.images.append(new_image)
|
| 66 |
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
# Create a new texture and associate it with the added image
|
| 70 |
+
new_texture = Texture()
|
| 71 |
+
new_texture.source = len(gltf.images) - 1 # Index of the newly added image
|
| 72 |
+
new_texture.sampler = 0
|
| 73 |
+
# set to nearest neighbor
|
| 74 |
+
|
| 75 |
+
gltf.textures.append(new_texture)
|
| 76 |
+
|
| 77 |
+
# Step 4: Assign the new texture to the appropriate material(s) or mesh(es)
|
| 78 |
+
# Assuming you have a mesh/primitive that was using the old texture and you want to apply the new texture to it, you need to set the material index for that mesh/primitive.
|
| 79 |
+
# Replace 0 with the actual index of the mesh/primitive you want to update.
|
| 80 |
+
gltf.materials[0].pbrMetallicRoughness.baseColorTexture.index = len(gltf.textures) - 1
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# Now you can convert the images to data URIs and save the updated GLB
|
| 84 |
+
gltf.convert_images(ImageFormat.DATAURI)
|
| 85 |
+
|
| 86 |
+
output_3d_model = "output_3d_model.glb"
|
| 87 |
+
gltf.save(output_3d_model)
|
| 88 |
+
else:
|
| 89 |
+
print("Invalid existing_texture_index")
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# Return the generated image and the processed model
|
| 93 |
+
return os.path.join(f"Stable_Diffusion_Finetuned_Minecraft_Skin_Generator/output_minecraft_skins/{output_image_name}"), output_3d_model
|
| 94 |
+
|
| 95 |
+
|
| 96 |
|
| 97 |
# Define Gradio UI components
|
| 98 |
prompt = gr.Textbox(label="Your Prompt", info="What the Minecraft Skin should look like")
|
|
|
|
| 118 |
output_image_name,
|
| 119 |
verbose
|
| 120 |
],
|
| 121 |
+
outputs=[
|
| 122 |
+
gr.Image(label="Generated Minecraft Skin Image Asset"),
|
| 123 |
+
gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model")
|
| 124 |
+
],
|
| 125 |
title="Minecraft Skin Generator",
|
| 126 |
description="Make AI generated Minecraft Skins by a Finetuned Stable Diffusion Version!<br>Model used: https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator<br>Hugging Face Space made by [Nick088](https://linktr.ee/Nick088)",
|
| 127 |
).launch(show_api=False, share=True)
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
imagemagick
|
requirements.txt
CHANGED
|
@@ -3,4 +3,6 @@ transformers
|
|
| 3 |
diffusers
|
| 4 |
accelerate
|
| 5 |
gradio
|
| 6 |
-
scipy
|
|
|
|
|
|
|
|
|
| 3 |
diffusers
|
| 4 |
accelerate
|
| 5 |
gradio
|
| 6 |
+
scipy
|
| 7 |
+
Pillow===9.0.1
|
| 8 |
+
pygltflib
|