Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,11 +18,11 @@ else:
|
|
| 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"
|
|
@@ -32,65 +32,13 @@ def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_
|
|
| 32 |
inference_command = f"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 |
-
|
| 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}"),
|
| 94 |
|
| 95 |
|
| 96 |
|
|
|
|
| 18 |
|
| 19 |
subprocess.run(["git", "clone", "https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator.git"])
|
| 20 |
|
| 21 |
+
os.chdir("Stable_Diffusion_Finetuned_Minecraft_Skin_Generator")
|
| 22 |
+
|
| 23 |
|
| 24 |
@spaces.GPU()
|
| 25 |
def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, output_image_name, verbose):
|
|
|
|
|
|
|
| 26 |
|
| 27 |
if stable_diffusion_model == '2':
|
| 28 |
sd_model = "minecraft-skins"
|
|
|
|
| 32 |
inference_command = f"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 |
|
| 37 |
+
os.system("python Scripts/to_3d_model.py")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# Return the generated image and the processed model
|
| 41 |
+
return os.path.join(f"Stable_Diffusion_Finetuned_Minecraft_Skin_Generator/output_minecraft_skins/{output_image_name}"), os.path.join(f"Stable_Diffusion_Finetuned_Minecraft_Skin_Generator/output_minecraft_skins/{output_image_name}_3d_model.glb")
|
| 42 |
|
| 43 |
|
| 44 |
|