prithivMLmods commited on
Commit
4ebd17a
1 Parent(s): 8669172

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
app.py CHANGED
@@ -1,12 +1,4 @@
1
  #!/usr/bin/env python
2
- # Permission is hereby granted, free of charge, to any person obtaining a copy
3
- # of this software and associated documentation files (the "Software"), to deal
4
- # in the Software without restriction, including without limitation the rights
5
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
- # copies of the Software, and to permit persons to whom the Software is
7
- # furnished to do so, subject to the following conditions:
8
- #
9
- # ...
10
  import os
11
  import random
12
  import uuid
@@ -15,7 +7,7 @@ import numpy as np
15
  from PIL import Image
16
  import spaces
17
  import torch
18
- from diffusers import DiffusionPipeline, StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
19
 
20
  css = '''
21
  .gradio-container{max-width: 570px !important}
@@ -39,7 +31,7 @@ examples = [
39
  MODEL_OPTIONS = {
40
  "Lightning": "SG161222/RealVisXL_V4.0_Lightning",
41
  "Turbovision": "SG161222/RealVisXL_V3.0_Turbo",
42
- "FLUX.1-schnell": "black-forest-labs/FLUX.1-schnell",
43
  }
44
 
45
  MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
@@ -50,11 +42,10 @@ BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1"))
50
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
51
 
52
  def load_and_prepare_model(model_id):
53
- if model_id == "black-forest-labs/FLUX.1-schnell":
54
- pipe = DiffusionPipeline.from_pretrained(
55
  model_id,
56
- torch_dtype=torch.bfloat16,
57
- revision="refs/pr/1"
58
  ).to(device)
59
  else:
60
  pipe = StableDiffusionXLPipeline.from_pretrained(
@@ -266,7 +257,7 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
266
  outputs=[result, seed],
267
  api_name="run",
268
  )
269
- gr.Markdown("🥠Models used in the playground [[Lightning]](https://huggingface.co/SG161222/RealVisXL_V4.0_Lightning), [[Turbo]](https://huggingface.co/SG161222/RealVisXL_V3.0_Turbo) for image generation. stable diffusion xl piped (sdxl) model HF. This is the demo space for generating images using the Stable Diffusion XL models, with multi different variants available.")
270
  gr.Markdown("🥠This is the demo space for generating images using Stable Diffusion with quality styles, different 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>.")
271
  gr.Markdown("⚠️ users are accountable for the content they generate and are responsible for ensuring it meets appropriate ethical standards.")
272
 
@@ -275,4 +266,4 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
275
  predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())
276
 
277
  if __name__ == "__main__":
278
- demo.queue(max_size=20).launch(show_api=False)
 
1
  #!/usr/bin/env python
 
 
 
 
 
 
 
 
2
  import os
3
  import random
4
  import uuid
 
7
  from PIL import Image
8
  import spaces
9
  import torch
10
+ from diffusers import FluxPipeline, StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
11
 
12
  css = '''
13
  .gradio-container{max-width: 570px !important}
 
31
  MODEL_OPTIONS = {
32
  "Lightning": "SG161222/RealVisXL_V4.0_Lightning",
33
  "Turbovision": "SG161222/RealVisXL_V3.0_Turbo",
34
+ "FLUX.1-schnell": "black-forest-labs/FLUX.1-schnell"
35
  }
36
 
37
  MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
 
42
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
43
 
44
  def load_and_prepare_model(model_id):
45
+ if "FLUX" in model_id:
46
+ pipe = FluxPipeline.from_pretrained(
47
  model_id,
48
+ torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
 
49
  ).to(device)
50
  else:
51
  pipe = StableDiffusionXLPipeline.from_pretrained(
 
257
  outputs=[result, seed],
258
  api_name="run",
259
  )
260
+ gr.Markdown("🥠Models used in the playground [[Lightning]](https://huggingface.co/SG161222/RealVisXL_V4.0_Lightning), [[Turbo]](https://huggingface.co/SG161222/RealVisXL_V3.0_Turbo), [[FLUX]](https://huggingface.co/black-forest-labs/FLUX.1-schnell) for image generation. stable diffusion xl piped (sdxl) model HF. This is the demo space for generating images using the Stable Diffusion XL models, with multi different variants available.")
261
  gr.Markdown("🥠This is the demo space for generating images using Stable Diffusion with quality styles, different 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>.")
262
  gr.Markdown("⚠️ users are accountable for the content they generate and are responsible for ensuring it meets appropriate ethical standards.")
263
 
 
266
  predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())
267
 
268
  if __name__ == "__main__":
269
+ demo.queue(max_size=20).launch(show_api=False)