prithivMLmods commited on
Commit
d0ca33d
1 Parent(s): 2dfaa04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +126 -40
app.py CHANGED
@@ -1,5 +1,5 @@
1
  #!/usr/bin/env python
2
- # patch 1.0()
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
  # of this software and associated documentation files (the "Software"), to deal
5
  # in the Software without restriction, including without limitation the rights
@@ -19,7 +19,7 @@ import spaces
19
  import torch
20
  from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
21
 
22
- DESCRIPTIONz = """## STABLE IMAGINE 🍺
23
  """
24
 
25
  def save_image(img):
@@ -167,48 +167,134 @@ def load_predefined_images():
167
  "assets/4.png",
168
  "assets/5.png",
169
  "assets/6.png",
 
 
 
170
  ]
171
  return predefined_images
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
- with gr.Blocks(title="Stable Imagine 🍺", css=css) as demo:
175
- with gr.Row():
176
- gr.Markdown(DESCRIPTIONz)
177
- with gr.Row():
178
- with gr.Column():
179
- prompt = gr.Textbox(label="Prompt", max_lines=3, value=examples[0])
180
- style = gr.Dropdown(label="Style", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME, interactive=True)
181
- lora_model = gr.Dropdown(label="LoRA Models", choices=list(LORA_OPTIONS.keys()), value="Realism (face/character)👦🏻", interactive=True)
182
- width = gr.Slider(label="Width", minimum=256, maximum=2048, value=1024, step=64)
183
- height = gr.Slider(label="Height", minimum=256, maximum=2048, value=1024, step=64)
184
- seed = gr.Number(label="Seed", value=42, precision=0, interactive=True)
185
-
186
- with gr.Column():
187
- use_negative_prompt = gr.Checkbox(label="Use negative prompt?", value=True)
188
- negative_prompt = gr.Textbox(label="Negative Prompt", value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation", max_lines=3)
189
- randomize_seed = gr.Checkbox(label="Randomize Seed?", value=True)
190
- guidance_scale = gr.Slider(label="Guidance Scale", minimum=1, maximum=20, value=7, step=0.5)
191
- predefined_images = gr.Gallery(load_predefined_images(), label="Predefined Images", show_label=False, interactive=False).style(grid=4)
192
- generate_button = gr.Button("Generate")
193
- output_image = gr.Gallery(label="Output Image", show_label=False).style(grid=4)
194
- output_seed = gr.Number(label="Output Seed", interactive=False)
195
-
196
- generate_button.click(
197
- fn=generate,
198
- inputs=[
199
- prompt,
200
- negative_prompt,
201
- use_negative_prompt,
202
- seed,
203
- width,
204
- height,
205
- guidance_scale,
206
- randomize_seed,
207
- style,
208
- lora_model,
209
- ],
210
- outputs=[output_image, output_seed],
211
  )
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  if __name__ == "__main__":
214
- demo.queue().launch(share=False, debug=True)
 
1
  #!/usr/bin/env python
2
+ #patch 1.0()
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
  # of this software and associated documentation files (the "Software"), to deal
5
  # in the Software without restriction, including without limitation the rights
 
19
  import torch
20
  from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
21
 
22
+ DESCRIPTIONz= """## STABLE IMAGINE 🍺
23
  """
24
 
25
  def save_image(img):
 
167
  "assets/4.png",
168
  "assets/5.png",
169
  "assets/6.png",
170
+ "assets/7.png",
171
+ "assets/8.png",
172
+ "assets/9.png",
173
  ]
174
  return predefined_images
175
 
176
+ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
177
+ gr.Markdown(DESCRIPTIONz)
178
+ with gr.Group():
179
+ with gr.Row():
180
+ prompt = gr.Text(
181
+ label="Prompt",
182
+ show_label=False,
183
+ max_lines=1,
184
+ placeholder="Enter your prompt with resp. tag!",
185
+ container=False,
186
+ )
187
+ run_button = gr.Button("Run", scale=0)
188
+ result = gr.Gallery(label="Result", columns=1, preview=True, show_label=False)
189
+
190
+ with gr.Accordion("Advanced options", open=False, visible=False):
191
+ use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
192
+ negative_prompt = gr.Text(
193
+ label="Negative prompt",
194
+ lines=4,
195
+ max_lines=6,
196
+ value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
197
+ placeholder="Enter a negative prompt",
198
+ visible=True,
199
+ )
200
+ seed = gr.Slider(
201
+ label="Seed",
202
+ minimum=0,
203
+ maximum=MAX_SEED,
204
+ step=1,
205
+ value=0,
206
+ visible=True
207
+ )
208
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
209
+
210
+ with gr.Row(visible=True):
211
+ width = gr.Slider(
212
+ label="Width",
213
+ minimum=512,
214
+ maximum=2048,
215
+ step=8,
216
+ value=1024,
217
+ )
218
+ height = gr.Slider(
219
+ label="Height",
220
+ minimum=512,
221
+ maximum=2048,
222
+ step=8,
223
+ value=1024,
224
+ )
225
+
226
+ with gr.Row():
227
+ guidance_scale = gr.Slider(
228
+ label="Guidance Scale",
229
+ minimum=0.1,
230
+ maximum=20.0,
231
+ step=0.1,
232
+ value=3.0,
233
+ )
234
 
235
+ style_selection = gr.Radio(
236
+ show_label=True,
237
+ container=True,
238
+ interactive=True,
239
+ choices=STYLE_NAMES,
240
+ value=DEFAULT_STYLE_NAME,
241
+ label="Quality Style",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  )
243
 
244
+ with gr.Row(visible=True):
245
+ model_choice = gr.Dropdown(
246
+ label="LoRA Selection",
247
+ choices=list(LORA_OPTIONS.keys()),
248
+ value="Realism (face/character)👦🏻"
249
+ )
250
+
251
+ gr.Examples(
252
+ examples=examples,
253
+ inputs=prompt,
254
+ outputs=[result, seed],
255
+ fn=generate,
256
+ cache_examples=False,
257
+ )
258
+
259
+ use_negative_prompt.change(
260
+ fn=lambda x: gr.update(visible=x),
261
+ inputs=use_negative_prompt,
262
+ outputs=negative_prompt,
263
+ api_name=False,
264
+ )
265
+
266
+ gr.on(
267
+ triggers=[
268
+ prompt.submit,
269
+ negative_prompt.submit,
270
+ run_button.click,
271
+ ],
272
+ fn=generate,
273
+ inputs=[
274
+ prompt,
275
+ negative_prompt,
276
+ use_negative_prompt,
277
+ seed,
278
+ width,
279
+ height,
280
+ guidance_scale,
281
+ randomize_seed,
282
+ style_selection,
283
+ model_choice,
284
+ ],
285
+ outputs=[result, seed],
286
+ api_name="run",
287
+ )
288
+
289
+
290
+ with gr.Column(scale=3):
291
+ gr.Markdown("### Image Gallery")
292
+ predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())
293
+
294
+ gr.Markdown("🍺Models used in the playground [[Lightning]](https://huggingface.co/SG161222/RealVisXL_V4.0_Lightning) & LoRA from [[LoRA]](https://huggingface.co/collections/prithivMLmods/dev-models-667803a6d5ac75b59110e527) for image generation. The specific LoRA in the space that requires appropriate trigger words brings good results. The model is still in the training phase. This is not the final version and may contain artifacts and perform poorly in some cases.")
295
+ gr.Markdown("🍺This is the demo space for generating images using Stable Diffusion with quality styles, different LoRA models and types. Try the sample prompts to generate higher quality images. Try the sample prompts for generating higher quality images.<a href='https://huggingface.co/spaces/prithivMLmods/Top-Prompt-Collection' target='_blank'>Try prompts</a>.")
296
+ gr.Markdown("🍺Make sure that the prompts passed meet the trigger word conditions and are well-detailed. This space is for educational purposes only; using it productively is meant for your own knowledge.")
297
+ gr.Markdown("⚠️ users are accountable for the content they generate and are responsible for ensuring it meets appropriate ethical standards.")
298
+
299
  if __name__ == "__main__":
300
+ demo.queue(max_size=30).launch()