Nick088 commited on
Commit
9836998
Β·
verified Β·
1 Parent(s): 1a381cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -52
app.py CHANGED
@@ -23,7 +23,7 @@ os.chdir("Stable_Diffusion_Finetuned_Minecraft_Skin_Generator")
23
 
24
 
25
  @spaces.GPU()
26
- def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, filename, verbose):
27
 
28
  if stable_diffusion_model == '2':
29
  sd_model = "minecraft-skins"
@@ -35,56 +35,59 @@ def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_
35
  os.system(inference_command)
36
 
37
  # view it in 3d
38
- os.chdir("Scripts")
39
- command_3d_model = f"python to_3d_model.py '{filename}'"
40
- os.system(command_3d_model)
41
- os.chdir("..")
42
- glb_path = os.path.join(f"output_minecraft_skins/{filename}_3d_model.glb")
43
- return os.path.join(f"output_minecraft_skins/{filename}"), glb_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
 
45
 
46
- def custom_output(image_path, glb_path):
47
- if glb_path is None:
48
- return image_path
49
- else:
50
- return [image_path, gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model", path=glb_path)]
51
-
52
-
53
- with gr.Blocks() as minecraft_skin_generator:
54
- with gr.Row():
55
- prompt = gr.Textbox(label="Your Prompt", info="What the Minecraft Skin should look like")
56
- stable_diffusion_model = gr.Dropdown(['2', 'xl'], value="xl", label="Stable Diffusion Model", info="Choose which Stable Diffusion Model to use, xl understands prompts better")
57
- num_inference_steps = gr.Number(label="Number of Inference Steps", precision=0, value=25)
58
- guidance_scale = gr.Number(minimum=0.1, value=7.5, label="Guidance Scale", info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference")
59
- 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")
60
- seed = gr.Number(value=42, label="Seed", info="A starting point to initiate generation, put 0 for a random one")
61
- 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")
62
- verbose = gr.Checkbox(label="Verbose Output", info="Produce more detailed output while running", value=False)
63
- see_in_3d = gr.Checkbox(label="See in 3D", info="View the generated skin in 3D", value=False)
64
-
65
- image_path, glb_path = run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, filename, verbose)
66
-
67
- with gr.Row():
68
- output = gr.Image(label="Generated Minecraft Skin Image Asset")
69
- if see_in_3d:
70
- output.style(height=500)
71
- output.style(width=500)
72
- output.style(display="flex")
73
- output.style(justify_content="center")
74
- output.style(align_items="center")
75
- output.style(flex_wrap="wrap")
76
- output.style(grid_template_columns="repeat(auto-fill, minmax(250px, 1fr))")
77
- output.style(grid_gap="10px")
78
- output.style(overflow="auto")
79
- output.style(padding="10px")
80
- output.style(box_sizing="border-box")
81
- output.style(border="1px solid #ccc")
82
- output.style(border_radius="5px")
83
- output.style(margin="10px 0")
84
- output.style(background_color="#f9f9f9")
85
-
86
- output.render(custom_output, inputs=[image_path, glb_path])
87
- else:
88
- output.render(image_path)
89
-
90
- minecraft_skin_generator.launch(show_api=False, share=True)
 
23
 
24
 
25
  @spaces.GPU()
26
+ def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, filename, verbose, see_in_3d):
27
 
28
  if stable_diffusion_model == '2':
29
  sd_model = "minecraft-skins"
 
35
  os.system(inference_command)
36
 
37
  # view it in 3d
38
+ if see_in_3d:
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
+
48
+
49
+ # Define Gradio UI components
50
+ prompt = gr.Textbox(label="Your Prompt", info="What the Minecraft Skin should look like")
51
+ stable_diffusion_model = gr.Dropdown(['2', 'xl'], value="xl", label="Stable Diffusion Model", info="Choose which Stable Diffusion Model to use, xl understands prompts better")
52
+ num_inference_steps = gr.Number(label="Number of Inference Steps", precision=0, value=25)
53
+ guidance_scale = gr.Number(minimum=0.1, value=7.5, label="Guidance Scale", info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference")
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
+ verbose = gr.Checkbox(label="Verbose Output", info="Produce more detailed output while running", value=False)
58
+ see_in_3d = gr.Checkbox(label="See in 3D", info="View the generated skin in 3D", value=False)
59
+
60
+ title="<h1>Minecraft Skin Generator</h1>"
61
+ 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)"
62
+
63
+ with gr.Blocks() as demo:
64
+ gr.Markdown(title)
65
+ gr.Markdown(description)
66
+ gr.Column():
67
+ with gr.Column(visible=False) as output:
68
+ inputs=[
69
+ prompt,
70
+ stable_diffusion_model,
71
+ num_inference_steps,
72
+ guidance_scale,
73
+ model_precision_type,
74
+ seed,
75
+ filename,
76
+ verbose,
77
+ see_in_3d
78
+ ]
79
+ outputs=[
80
+ gr.Image(label="Generated Minecraft Skin Image Asset"),
81
+ gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model")
82
+ ]
83
+ submit_btn.click(
84
+ run_inference,
85
+ inputs,
86
+ outputs,
87
+ )
88
+
89
 
90
+
91
 
92
+
93
+ demo.launch(show_api=False, share=True)