Nick088 commited on
Commit
b3925d0
1 Parent(s): 2ecb2cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -3,8 +3,8 @@ from diffusers import StableDiffusion3Pipeline
3
  import gradio as gr
4
  import os
5
  import transformers
 
6
  from transformers import T5Tokenizer, T5ForConditionalGeneration
7
- from huggingface_hub import snapshot_download
8
  import spaces
9
 
10
  HF_TOKEN = os.getenv("HF_TOKEN")
@@ -16,18 +16,11 @@ else:
16
  device = "cpu"
17
  print("Using CPU")
18
 
19
- # download sd3 medium weights
20
- model_path = snapshot_download(
21
- repo_id="stabilityai/stable-diffusion-3-medium",
22
- revision="refs/pr/26",
23
- repo_type="model",
24
- ignore_patterns=["*.md", "*..gitattributes"],
25
- local_dir="stable-diffusion-3-medium",
26
- token=HF_TOKEN,
27
- )
28
 
 
29
 
30
- # Initialize the pipeline and download the model
 
31
  pipe = StableDiffusion3Pipeline.from_pretrained(model_path, torch_dtype=torch.float16)
32
  pipe.to(device)
33
 
@@ -81,15 +74,15 @@ enhance_prompt = gr.Checkbox(label="Prompt Enhancement", info="Enhance your prom
81
 
82
  negative_prompt = gr.Textbox(label="Negative Prompt", info="Describe what you don't want in the image", value="deformed, distorted, disfigured, poorly drawn, bad anatomy, incorrect anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation", placeholder="Ugly, bad anatomy...")
83
 
84
- num_inference_steps = gr.Number(label="Number of Inference Steps", precision=0, value=25)
85
 
86
- height = gr.Slider(label="Height", info="Height of the Image", minimum=256, maximum="1536", step=32, value=1024)
87
 
88
- width = gr.Slider(label="Width", info="Width of the Image", minimum=256, maximum="1536", step=32, value=1024)
89
 
90
- 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")
91
 
92
- seed = gr.Slider(value=42, minimum=0, maximum=2**32-1, step=1, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
93
 
94
  num_images_per_prompt = gr.Slider(label="Number of Images to generate with the settings",minimum=1, maximum=4, step=1, value=1)
95
 
 
3
  import gradio as gr
4
  import os
5
  import transformers
6
+ import numpy as np
7
  from transformers import T5Tokenizer, T5ForConditionalGeneration
 
8
  import spaces
9
 
10
  HF_TOKEN = os.getenv("HF_TOKEN")
 
16
  device = "cpu"
17
  print("Using CPU")
18
 
 
 
 
 
 
 
 
 
 
19
 
20
+ MAX_SEED = np.iinfo(np.int32).max
21
 
22
+
23
+ # Initialize the pipeline and download the sd3 medium model
24
  pipe = StableDiffusion3Pipeline.from_pretrained(model_path, torch_dtype=torch.float16)
25
  pipe.to(device)
26
 
 
74
 
75
  negative_prompt = gr.Textbox(label="Negative Prompt", info="Describe what you don't want in the image", value="deformed, distorted, disfigured, poorly drawn, bad anatomy, incorrect anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation", placeholder="Ugly, bad anatomy...")
76
 
77
+ num_inference_steps = gr.Number(label="Number of Inference Steps", 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", precision=0, value=25)
78
 
79
+ height = gr.Slider(label="Height", info="Height of the Image", minimum=256, maximum=1344, step=32, value=1024)
80
 
81
+ width = gr.Slider(label="Width", info="Width of the Image", minimum=256, maximum=1344, step=32, value=1024)
82
 
83
+ guidance_scale = gr.Slider(label="Guidance Scale", info="Controls how much the image generation process follows the text prompt. Higher values make the image stick more closely to the input text.", minimum=0.0, maximum=10.0, value=7.5, step=0.1)
84
 
85
+ seed = gr.Slider(value=42, minimum=0, maximum=MAX_SEED, step=1, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
86
 
87
  num_images_per_prompt = gr.Slider(label="Number of Images to generate with the settings",minimum=1, maximum=4, step=1, value=1)
88