Nick088 commited on
Commit
15e5c89
β€’
1 Parent(s): 8a3e9b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
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,20 +35,17 @@ def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_
35
  os.system(inference_command)
36
 
37
  # view it in 3d
 
 
 
 
 
 
 
 
 
38
 
39
- os.chdir("Scripts")
40
-
41
- command_3d_model = f"python to_3d_model.py '{filename}'"
42
-
43
- os.system(command_3d_model)
44
-
45
- os.chdir("..")
46
-
47
- # Return the generated image and the processed model
48
- return os.path.join(f"output_minecraft_skins/{filename}"), os.path.join(f"output_minecraft_skins/{filename}_3d_model.glb")
49
 
50
-
51
-
52
  # Define Gradio UI components
53
  prompt = gr.Textbox(label="Your Prompt", info="What the Minecraft Skin should look like")
54
  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")
@@ -56,8 +53,9 @@ num_inference_steps = gr.Number(label="Number of Inference Steps", precision=0,
56
  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")
57
  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")
58
  seed = gr.Number(value=42, label="Seed", info="A starting point to initiate generation, put 0 for a random one")
59
- 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")
60
  verbose = gr.Checkbox(label="Verbose Output", info="Produce more detailed output while running", value=False)
 
61
 
62
 
63
  # Create the Gradio interface
@@ -71,12 +69,12 @@ gr.Interface(
71
  model_precision_type,
72
  seed,
73
  filename,
74
- verbose
 
75
  ],
76
  outputs=[
77
  gr.Image(label="Generated Minecraft Skin Image Asset"),
78
  gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model")
79
  ],
80
  title="Minecraft Skin Generator",
81
- 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)",
82
- ).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")
 
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
 
61
  # Create the Gradio interface
 
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
  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)