Spaces:
Running
on
Zero
Running
on
Zero
prithivMLmods
commited on
Commit
•
02ab1fb
1
Parent(s):
4ebd17a
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import numpy as np
|
|
7 |
from PIL import Image
|
8 |
import spaces
|
9 |
import torch
|
10 |
-
from diffusers import
|
11 |
|
12 |
css = '''
|
13 |
.gradio-container{max-width: 570px !important}
|
@@ -31,7 +31,7 @@ examples = [
|
|
31 |
MODEL_OPTIONS = {
|
32 |
"Lightning": "SG161222/RealVisXL_V4.0_Lightning",
|
33 |
"Turbovision": "SG161222/RealVisXL_V3.0_Turbo",
|
34 |
-
|
35 |
}
|
36 |
|
37 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
|
@@ -42,19 +42,13 @@ BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1"))
|
|
42 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
43 |
|
44 |
def load_and_prepare_model(model_id):
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
model_id,
|
53 |
-
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
54 |
-
use_safetensors=True,
|
55 |
-
add_watermarker=False,
|
56 |
-
).to(device)
|
57 |
-
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
58 |
|
59 |
if USE_TORCH_COMPILE:
|
60 |
pipe.compile()
|
@@ -64,7 +58,7 @@ def load_and_prepare_model(model_id):
|
|
64 |
|
65 |
return pipe
|
66 |
|
67 |
-
# Preload and compile
|
68 |
models = {key: load_and_prepare_model(value) for key, value in MODEL_OPTIONS.items()}
|
69 |
|
70 |
MAX_SEED = np.iinfo(np.int32).max
|
@@ -257,7 +251,7 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
|
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)
|
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,4 +260,4 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
|
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)
|
|
|
7 |
from PIL import Image
|
8 |
import spaces
|
9 |
import torch
|
10 |
+
from diffusers import 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 |
+
|
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 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
46 |
+
model_id,
|
47 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
48 |
+
use_safetensors=True,
|
49 |
+
add_watermarker=False,
|
50 |
+
).to(device)
|
51 |
+
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
if USE_TORCH_COMPILE:
|
54 |
pipe.compile()
|
|
|
58 |
|
59 |
return pipe
|
60 |
|
61 |
+
# Preload and compile both models
|
62 |
models = {key: load_and_prepare_model(value) for key, value in MODEL_OPTIONS.items()}
|
63 |
|
64 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
251 |
outputs=[result, seed],
|
252 |
api_name="run",
|
253 |
)
|
254 |
+
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.")
|
255 |
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>.")
|
256 |
gr.Markdown("⚠️ users are accountable for the content they generate and are responsible for ensuring it meets appropriate ethical standards.")
|
257 |
|
|
|
260 |
predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())
|
261 |
|
262 |
if __name__ == "__main__":
|
263 |
+
demo.queue(max_size=20).launch(show_api=False)
|