Nick088 commited on
Commit
1a381cb
β€’
1 Parent(s): c43cd70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -48
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, see_in_3d):
27
 
28
  if stable_diffusion_model == '2':
29
  sd_model = "minecraft-skins"
@@ -35,57 +35,56 @@ def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_
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=True)
59
-
60
-
61
- # Create the Gradio interface
62
- interface = gr.Interface(
63
- fn=run_inference,
64
- inputs=[
65
- prompt,
66
- stable_diffusion_model,
67
- num_inference_steps,
68
- guidance_scale,
69
- model_precision_type,
70
- seed,
71
- filename,
72
- verbose,
73
- see_in_3d
74
- ],
75
- outputs=[
76
- gr.Image(label="Generated Minecraft Skin Image Asset")
77
- ],
78
- title="Minecraft Skin Generator",
79
- 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)"
80
- )
81
-
82
- # Add a custom output component that displays the 3D model if the "See in 3D" input is True
83
  def custom_output(image_path, glb_path):
84
  if glb_path is None:
85
  return image_path
86
  else:
87
  return [image_path, gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model", path=glb_path)]
88
 
89
- interface.add_output(custom_output, inputs=[interface.output[0], interface.input[8]])
90
 
91
- interface.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):
27
 
28
  if stable_diffusion_model == '2':
29
  sd_model = "minecraft-skins"
 
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)