Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,28 +20,21 @@ os.chdir("Stable_Diffusion_Finetuned_Minecraft_Skin_Generator")
|
|
| 20 |
|
| 21 |
|
| 22 |
@spaces.GPU()
|
| 23 |
-
def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, filename,
|
| 24 |
|
| 25 |
# inference
|
| 26 |
if stable_diffusion_model == '2':
|
| 27 |
sd_model = "minecraft-skins"
|
| 28 |
-
|
| 29 |
sd_model = "minecraft-skins-sdxl"
|
| 30 |
|
| 31 |
-
inference_command = f"python Scripts/{sd_model}.py '{prompt}' {num_inference_steps} {guidance_scale} {model_precision_type} {seed} {filename} {'--verbose' if verbose else ''}"
|
| 32 |
|
| 33 |
os.system(inference_command)
|
| 34 |
|
| 35 |
-
# view it
|
| 36 |
-
if
|
| 37 |
-
|
| 38 |
-
from pygltflib.utils import ImageFormat, Texture, Material, Image as GLTFImage
|
| 39 |
-
os.chdir("Scripts")
|
| 40 |
-
command_3d_model = f"python to_3d_model.py '{filename}'"
|
| 41 |
-
os.system(command_3d_model)
|
| 42 |
-
os.chdir("..")
|
| 43 |
-
glb_path = os.path.join(f"output_minecraft_skins/{filename}_3d_model.glb")
|
| 44 |
-
return os.path.join(f"output_minecraft_skins/{filename}"), glb_path
|
| 45 |
else:
|
| 46 |
return os.path.join(f"output_minecraft_skins/{filename}"), None
|
| 47 |
|
|
@@ -54,7 +47,7 @@ guidance_scale = gr.Number(minimum=0.1, value=7.5, label="Guidance Scale", info=
|
|
| 54 |
model_precision_type = gr.Dropdown(["fp16", "fp32"], value="fp16", label="Model Precision Type", info="The precision type to load the model, like fp16 which is faster, or fp32 which gives better results")
|
| 55 |
seed = gr.Number(value=42, label="Seed", info="A starting point to initiate generation, put 0 for a random one")
|
| 56 |
filename = gr.Textbox(label="Output Image Name", info="The name of the file of the output image skin, keep the.png", value="output-skin.png")
|
| 57 |
-
|
| 58 |
verbose = gr.Checkbox(label="Verbose Output", info="Produce more detailed output while running", value=False)
|
| 59 |
|
| 60 |
|
|
@@ -69,12 +62,12 @@ gr.Interface(
|
|
| 69 |
model_precision_type,
|
| 70 |
seed,
|
| 71 |
filename,
|
| 72 |
-
|
| 73 |
verbose
|
| 74 |
],
|
| 75 |
outputs=[
|
| 76 |
gr.Image(label="Generated Minecraft Skin Image Asset"),
|
| 77 |
-
gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model")
|
| 78 |
],
|
| 79 |
title="Minecraft Skin Generator",
|
| 80 |
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>Credits: [Monadical-SAS](https://github.com/Monadical-SAS/minecraft_skin_generator) (Creators of the model), [Nick088](https://linktr.ee/Nick088) (Improving usage of the model), daroche (helping me fix the 3d model texture isue), [Brottweiler](https://gist.github.com/Brottweiler/483d0856c6692ef70cf90bf1a85ce364)(script to fix the 3d model texture, [meew](https://huggingface.co/spaces/meeww/Minecraft_Skin_Generator/blob/main/models/player_model.glb) (Minecraft Player 3d model)",
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
@spaces.GPU()
|
| 23 |
+
def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, filename, model_3d, verbose):
|
| 24 |
|
| 25 |
# inference
|
| 26 |
if stable_diffusion_model == '2':
|
| 27 |
sd_model = "minecraft-skins"
|
| 28 |
+
elif stable_diffusion_model == 'xl':
|
| 29 |
sd_model = "minecraft-skins-sdxl"
|
| 30 |
|
| 31 |
+
inference_command = f"python Scripts/{sd_model}.py '{prompt}' {num_inference_steps} {guidance_scale} {model_precision_type} {seed} {filename} {'--model_3d' if model_3d else ''} {'--verbose' if verbose else ''}"
|
| 32 |
|
| 33 |
os.system(inference_command)
|
| 34 |
|
| 35 |
+
# view it also as 3d model or not output
|
| 36 |
+
if model_3d:
|
| 37 |
+
return os.path.join(f"output_minecraft_skins/{filename}"), glb_pathos.path.join(f"output_minecraft_skins/{filename}_3d_model.glb")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
else:
|
| 39 |
return os.path.join(f"output_minecraft_skins/{filename}"), None
|
| 40 |
|
|
|
|
| 47 |
model_precision_type = gr.Dropdown(["fp16", "fp32"], value="fp16", label="Model Precision Type", info="The precision type to load the model, like fp16 which is faster, or fp32 which gives better results")
|
| 48 |
seed = gr.Number(value=42, label="Seed", info="A starting point to initiate generation, put 0 for a random one")
|
| 49 |
filename = gr.Textbox(label="Output Image Name", info="The name of the file of the output image skin, keep the.png", value="output-skin.png")
|
| 50 |
+
model_3d = gr.Checkbox(label="See in 3D", info="View the generated skin as a 3D Model", value=True)
|
| 51 |
verbose = gr.Checkbox(label="Verbose Output", info="Produce more detailed output while running", value=False)
|
| 52 |
|
| 53 |
|
|
|
|
| 62 |
model_precision_type,
|
| 63 |
seed,
|
| 64 |
filename,
|
| 65 |
+
model_3d,
|
| 66 |
verbose
|
| 67 |
],
|
| 68 |
outputs=[
|
| 69 |
gr.Image(label="Generated Minecraft Skin Image Asset"),
|
| 70 |
+
gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model View of the Skin")
|
| 71 |
],
|
| 72 |
title="Minecraft Skin Generator",
|
| 73 |
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>Credits: [Monadical-SAS](https://github.com/Monadical-SAS/minecraft_skin_generator) (Creators of the model), [Nick088](https://linktr.ee/Nick088) (Improving usage of the model), daroche (helping me fix the 3d model texture isue), [Brottweiler](https://gist.github.com/Brottweiler/483d0856c6692ef70cf90bf1a85ce364)(script to fix the 3d model texture, [meew](https://huggingface.co/spaces/meeww/Minecraft_Skin_Generator/blob/main/models/player_model.glb) (Minecraft Player 3d model)",
|