Spaces:
Running
on
Zero
Running
on
Zero
CACHE_EXAMPLES
#3
by
prithivMLmods
- opened
app.py
CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
|
|
4 |
import random
|
5 |
import numpy as np
|
6 |
import spaces
|
7 |
-
|
8 |
|
9 |
if torch.cuda.is_available():
|
10 |
device = "cuda"
|
@@ -15,7 +15,7 @@ else:
|
|
15 |
|
16 |
|
17 |
MAX_SEED = np.iinfo(np.int32).max
|
18 |
-
|
19 |
|
20 |
# Initialize the pipeline and download the sdxl flash model
|
21 |
pipe = StableDiffusionXLPipeline.from_pretrained("sd-community/sdxl-flash", torch_dtype=torch.float16)
|
@@ -96,28 +96,16 @@ with gr.Blocks(css=css) as demo:
|
|
96 |
|
97 |
gr.Examples(
|
98 |
examples=examples,
|
99 |
-
inputs=[prompt],
|
100 |
-
outputs=[result],
|
101 |
fn=generate_image,
|
|
|
|
|
|
|
102 |
)
|
103 |
|
104 |
-
|
105 |
-
triggers=[
|
106 |
-
prompt.submit,
|
107 |
-
run_button.click,
|
108 |
-
],
|
109 |
fn=generate_image,
|
110 |
-
inputs=[
|
111 |
-
prompt,
|
112 |
-
negative_prompt,
|
113 |
-
num_inference_steps,
|
114 |
-
width,
|
115 |
-
height,
|
116 |
-
guidance_scale,
|
117 |
-
seed,
|
118 |
-
num_images_per_prompt,
|
119 |
-
],
|
120 |
outputs=[result],
|
121 |
)
|
122 |
|
123 |
-
demo.queue().launch(share
|
|
|
4 |
import random
|
5 |
import numpy as np
|
6 |
import spaces
|
7 |
+
import os
|
8 |
|
9 |
if torch.cuda.is_available():
|
10 |
device = "cuda"
|
|
|
15 |
|
16 |
|
17 |
MAX_SEED = np.iinfo(np.int32).max
|
18 |
+
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
|
19 |
|
20 |
# Initialize the pipeline and download the sdxl flash model
|
21 |
pipe = StableDiffusionXLPipeline.from_pretrained("sd-community/sdxl-flash", torch_dtype=torch.float16)
|
|
|
96 |
|
97 |
gr.Examples(
|
98 |
examples=examples,
|
|
|
|
|
99 |
fn=generate_image,
|
100 |
+
inputs=[prompt, negative_prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt],
|
101 |
+
outputs=[result],
|
102 |
+
cache_examples=CACHE_EXAMPLES
|
103 |
)
|
104 |
|
105 |
+
run_button.click(
|
|
|
|
|
|
|
|
|
106 |
fn=generate_image,
|
107 |
+
inputs=[prompt, negative_prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
outputs=[result],
|
109 |
)
|
110 |
|
111 |
+
demo.queue().launch(share=False)
|