Spaces:
				
			
			
	
			
			
		Running
		
			on 
			
			Zero
	
	
	
			
			
	
	
	
	
		
		
		Running
		
			on 
			
			Zero
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -14,38 +14,24 @@ else: | |
| 14 | 
             
            subprocess.run(["git", "clone", "https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator.git"])
         | 
| 15 | 
             
            os.chdir("Stable_Diffusion_Finetuned_Minecraft_Skin_Generator")
         | 
| 16 |  | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
                stable_diffusion_model,
         | 
| 21 | 
            -
                num_inference_steps,
         | 
| 22 | 
            -
                guidance_scale,
         | 
| 23 | 
            -
                num_images_per_prompt,
         | 
| 24 | 
            -
                model_precision_type,
         | 
| 25 | 
            -
                seed,
         | 
| 26 | 
            -
                output_image_name,
         | 
| 27 | 
            -
                verbose
         | 
| 28 | 
            -
            ):
         | 
| 29 | 
            -
                if verbose:
         | 
| 30 | 
            -
                    verbose_opt = '--verbose'
         | 
| 31 | 
             
                else:
         | 
| 32 | 
            -
                    verbose_opt = ''
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                if stable_diffusion_model == 'xl':
         | 
| 35 | 
             
                    sd_model = "minecraft-skins-sdxl"
         | 
| 36 | 
            -
                else:
         | 
| 37 | 
            -
                    sd_model = "minecraft-skins"
         | 
| 38 |  | 
| 39 | 
            -
                 | 
|  | |
|  | |
| 40 |  | 
| 41 | 
            -
                return  | 
| 42 |  | 
| 43 |  | 
| 44 | 
             
            prompt = gr.Textbox(label="Prompt", interactive=True)
         | 
| 45 |  | 
| 46 | 
             
            stable_diffusion_model = gr.Dropdown(["2", "xl"], interactive=True, label="Stable Diffusion Model", value="xl", info="Choose which Stable Diffusion Model to use, xl understands prompts better")
         | 
| 47 |  | 
| 48 | 
            -
            num_inference_steps = gr.Number(value=50, minimum=1, interactive=True, label="Inference Steps", | 
| 49 |  | 
| 50 | 
             
            guidance_scale = gr.Number(value=7.5, minimum=0.1, interactive=True, label="Guidance Scale", info="How closely the generated image adheres to the prompt")
         | 
| 51 |  | 
| @@ -59,6 +45,17 @@ output_image_name = gr.Textbox(label="Name of Generated Skin Output", interactiv | |
| 59 |  | 
| 60 | 
             
            verbose = gr.Checkbox(label="Verbose Output", interactive=True, value=False, info="Produce verbose output while running")
         | 
| 61 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 62 | 
             
            examples = [
         | 
| 63 | 
             
                [
         | 
| 64 | 
             
                    "A man in a purple suit wearing a tophat.",
         | 
| @@ -73,12 +70,23 @@ examples = [ | |
| 73 | 
             
                ]
         | 
| 74 | 
             
            ]
         | 
| 75 |  | 
|  | |
| 76 | 
             
            gr.Interface(
         | 
| 77 | 
            -
                fn= | 
| 78 | 
            -
                inputs=[ | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 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>Hugging Face Space made by [Nick088](https://linktr.ee/Nick088)",
         | 
| 82 | 
             
                examples=examples,
         | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
|  | 
|  | |
| 14 | 
             
            subprocess.run(["git", "clone", "https://github.com/Nick088Official/Stable_Diffusion_Finetuned_Minecraft_Skin_Generator.git"])
         | 
| 15 | 
             
            os.chdir("Stable_Diffusion_Finetuned_Minecraft_Skin_Generator")
         | 
| 16 |  | 
| 17 | 
            +
            def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, num_images_per_prompt, model_precision_type, output_image_name, verbose):
         | 
| 18 | 
            +
                if stable_diffusion_model == '2':
         | 
| 19 | 
            +
                    sd_model = "minecraft-skins"
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 20 | 
             
                else:
         | 
|  | |
|  | |
|  | |
| 21 | 
             
                    sd_model = "minecraft-skins-sdxl"
         | 
|  | |
|  | |
| 22 |  | 
| 23 | 
            +
                command = f"Python_Scripts/{sd_model}.py '{prompt}' {num_inference_steps} {guidance_scale} {num_images_per_prompt} {model_precision_type} {output_image_name} {'--verbose' if verbose else ''}"
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                subprocess.run(["python", command], shell=True, check=True)
         | 
| 26 |  | 
| 27 | 
            +
                return output_image_name
         | 
| 28 |  | 
| 29 |  | 
| 30 | 
             
            prompt = gr.Textbox(label="Prompt", interactive=True)
         | 
| 31 |  | 
| 32 | 
             
            stable_diffusion_model = gr.Dropdown(["2", "xl"], interactive=True, label="Stable Diffusion Model", value="xl", info="Choose which Stable Diffusion Model to use, xl understands prompts better")
         | 
| 33 |  | 
| 34 | 
            +
            num_inference_steps = gr.Number(value=50, minimum=1, interactive=True, label="Inference Steps",)
         | 
| 35 |  | 
| 36 | 
             
            guidance_scale = gr.Number(value=7.5, minimum=0.1, interactive=True, label="Guidance Scale", info="How closely the generated image adheres to the prompt")
         | 
| 37 |  | 
|  | |
| 45 |  | 
| 46 | 
             
            verbose = gr.Checkbox(label="Verbose Output", interactive=True, value=False, info="Produce verbose output while running")
         | 
| 47 |  | 
| 48 | 
            +
                
         | 
| 49 | 
            +
            # Define Gradio UI components
         | 
| 50 | 
            +
            prompt_input = gr.Textbox(label="Your Prompt", info="What the Minecraft Skin should look like")
         | 
| 51 | 
            +
            stable_diffusion_model_input = gr.Dropdown(['2', 'xl'], label="Stable Diffusion Model", info="Choose which Stable Diffusion Model to use, xl understands prompts better")
         | 
| 52 | 
            +
            num_inference_steps_input = gr.Number(label="Number of Inference Steps", precision=0, value=25)
         | 
| 53 | 
            +
            guidance_scale_input = 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 | 
            +
            num_images_per_prompt_input = gr.inputs.Number(minimum=1, value=1, precision=0, label="Number of Images per Prompt", info="The number of images to make with the prompt")
         | 
| 55 | 
            +
            model_precision_type_input = 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")
         | 
| 56 | 
            +
            output_image_name_input = 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_input = gr.Checkbox(label="Verbose Output", info="Produce more detailed output while running", value=False)
         | 
| 58 | 
            +
             | 
| 59 | 
             
            examples = [
         | 
| 60 | 
             
                [
         | 
| 61 | 
             
                    "A man in a purple suit wearing a tophat.",
         | 
|  | |
| 70 | 
             
                ]
         | 
| 71 | 
             
            ]
         | 
| 72 |  | 
| 73 | 
            +
            # Create the Gradio interface
         | 
| 74 | 
             
            gr.Interface(
         | 
| 75 | 
            +
                fn=run_inference,
         | 
| 76 | 
            +
                inputs=[
         | 
| 77 | 
            +
                    prompt_input,
         | 
| 78 | 
            +
                    stable_diffusion_model_input,
         | 
| 79 | 
            +
                    num_inference_steps_input,
         | 
| 80 | 
            +
                    guidance_scale_input,
         | 
| 81 | 
            +
                    num_images_per_prompt_input,
         | 
| 82 | 
            +
                    model_precision_type_input,
         | 
| 83 | 
            +
                    output_image_name_input,
         | 
| 84 | 
            +
                    verbose_input
         | 
| 85 | 
            +
                ],
         | 
| 86 | 
            +
                outputs=gr.outputs.Image(label="Generated Image"),
         | 
| 87 | 
            +
                title="Minecraft Skin Generator",
         | 
| 88 | 
             
                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>Hugging Face Space made by [Nick088](https://linktr.ee/Nick088)",
         | 
| 89 | 
             
                examples=examples,
         | 
| 90 | 
            +
            ).launch(show_api=False, share=True)
         | 
| 91 | 
            +
             | 
| 92 | 
            +
            # return os.path.join(f"output_minecraft_skins/{output_image_name}")
         | 
