osmr commited on
Commit
67b9dfb
·
verified ·
1 Parent(s): 608734f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -14,20 +14,25 @@ if torch.cuda.is_available():
14
  else:
15
  torch_dtype = torch.float32
16
 
 
17
  MAX_SEED = np.iinfo(np.int32).max
18
  MAX_IMAGE_SIZE = 1024
 
 
 
 
19
 
20
 
21
  # @spaces.GPU #[uncomment to use ZeroGPU]
22
  def infer(model_id: Optional[str] = "CompVis/stable-diffusion-v1-4",
23
  prompt: str = "",
24
  negative_prompt: str = "",
25
- seed: Optional[int] = 42,
26
  randomize_seed: bool = True,
27
- width: int = 1024,
28
- height: int = 1024,
29
- guidance_scale: Optional[float] = 7,
30
- num_inference_steps: Optional[int] = 20,
31
  progress = gr.Progress(track_tqdm=True)):
32
  if model_id:
33
  model_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
@@ -78,7 +83,7 @@ with gr.Blocks(css=css) as demo:
78
  multiselect=False,
79
  allow_custom_value=True,
80
  label="Model",
81
- info="Choose model ID",
82
  )
83
 
84
  with gr.Row():
@@ -99,7 +104,7 @@ with gr.Blocks(css=css) as demo:
99
  label="Negative prompt",
100
  max_lines=1,
101
  placeholder="Enter a negative prompt",
102
- visible=False,
103
  )
104
 
105
  seed = gr.Slider(
@@ -107,7 +112,7 @@ with gr.Blocks(css=css) as demo:
107
  minimum=0,
108
  maximum=MAX_SEED,
109
  step=1,
110
- value=0,
111
  )
112
 
113
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
@@ -118,7 +123,7 @@ with gr.Blocks(css=css) as demo:
118
  minimum=256,
119
  maximum=MAX_IMAGE_SIZE,
120
  step=32,
121
- value=1024, # Replace with defaults that work for your model
122
  )
123
 
124
  height = gr.Slider(
@@ -126,7 +131,7 @@ with gr.Blocks(css=css) as demo:
126
  minimum=256,
127
  maximum=MAX_IMAGE_SIZE,
128
  step=32,
129
- value=1024, # Replace with defaults that work for your model
130
  )
131
 
132
  with gr.Row():
@@ -135,7 +140,7 @@ with gr.Blocks(css=css) as demo:
135
  minimum=0.0,
136
  maximum=10.0,
137
  step=0.1,
138
- value=0.0, # Replace with defaults that work for your model
139
  )
140
 
141
  num_inference_steps = gr.Slider(
@@ -143,7 +148,7 @@ with gr.Blocks(css=css) as demo:
143
  minimum=1,
144
  maximum=50,
145
  step=1,
146
- value=2, # Replace with defaults that work for your model
147
  )
148
 
149
  gr.Examples(examples=examples, inputs=[prompt])
 
14
  else:
15
  torch_dtype = torch.float32
16
 
17
+ DEFAULT_SEED = 42
18
  MAX_SEED = np.iinfo(np.int32).max
19
  MAX_IMAGE_SIZE = 1024
20
+ DEFAULT_WIDTH = 1024
21
+ DEFAULT_HEIGHT = 1024
22
+ DEFAULT_GS = 0.0
23
+ DEFAULT_NUM_INF_STEPS = 20
24
 
25
 
26
  # @spaces.GPU #[uncomment to use ZeroGPU]
27
  def infer(model_id: Optional[str] = "CompVis/stable-diffusion-v1-4",
28
  prompt: str = "",
29
  negative_prompt: str = "",
30
+ seed: Optional[int] = DEFAULT_SEED,
31
  randomize_seed: bool = True,
32
+ width: int = DEFAULT_WIDTH,
33
+ height: int = DEFAULT_HEIGHT,
34
+ guidance_scale: Optional[float] = DEFAULT_GS,
35
+ num_inference_steps: Optional[int] = DEFAULT_NUM_INF_STEPS,
36
  progress = gr.Progress(track_tqdm=True)):
37
  if model_id:
38
  model_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
 
83
  multiselect=False,
84
  allow_custom_value=True,
85
  label="Model",
86
+ #info="Choose model ID",
87
  )
88
 
89
  with gr.Row():
 
104
  label="Negative prompt",
105
  max_lines=1,
106
  placeholder="Enter a negative prompt",
107
+ visible=True,
108
  )
109
 
110
  seed = gr.Slider(
 
112
  minimum=0,
113
  maximum=MAX_SEED,
114
  step=1,
115
+ value=DEFAULT_SEED,
116
  )
117
 
118
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
 
123
  minimum=256,
124
  maximum=MAX_IMAGE_SIZE,
125
  step=32,
126
+ value=DEFAULT_WIDTH, # Replace with defaults that work for your model
127
  )
128
 
129
  height = gr.Slider(
 
131
  minimum=256,
132
  maximum=MAX_IMAGE_SIZE,
133
  step=32,
134
+ value=DEFAULT_HEIGHT, # Replace with defaults that work for your model
135
  )
136
 
137
  with gr.Row():
 
140
  minimum=0.0,
141
  maximum=10.0,
142
  step=0.1,
143
+ value=DEFAULT_GS, # Replace with defaults that work for your model
144
  )
145
 
146
  num_inference_steps = gr.Slider(
 
148
  minimum=1,
149
  maximum=50,
150
  step=1,
151
+ value=DEFAULT_NUM_INF_STEPS, # Replace with defaults that work for your model
152
  )
153
 
154
  gr.Examples(examples=examples, inputs=[prompt])