Update app.py
Browse files
app.py
CHANGED
@@ -1,62 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
import random
|
4 |
-
|
5 |
-
# import spaces #[uncomment to use ZeroGPU]
|
6 |
from diffusers import DiffusionPipeline
|
7 |
-
import torch
|
8 |
|
9 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
model_repo_id = "runwayml/stable-diffusion-v1-5" # Replace to the model you would like to use
|
11 |
|
12 |
-
|
13 |
-
torch_dtype = torch.float16
|
14 |
-
else:
|
15 |
-
torch_dtype = torch.float32
|
16 |
-
|
17 |
-
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
18 |
-
pipe = pipe.to(device)
|
19 |
pipe.load_lora_weights("OVAWARE/plixel-minecraft")
|
20 |
|
21 |
-
MAX_SEED = np.iinfo(np.int32).max
|
22 |
-
MAX_IMAGE_SIZE = 1024
|
23 |
-
|
24 |
|
25 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
26 |
def infer(
|
27 |
-
prompt
|
28 |
-
negative_prompt,
|
29 |
-
seed,
|
30 |
-
randomize_seed,
|
31 |
-
width,
|
32 |
-
height,
|
33 |
-
guidance_scale,
|
34 |
-
num_inference_steps,
|
35 |
-
progress=gr.Progress(track_tqdm=True),
|
36 |
):
|
37 |
-
if randomize_seed:
|
38 |
-
seed = random.randint(0, MAX_SEED)
|
39 |
-
|
40 |
-
generator = torch.Generator().manual_seed(seed)
|
41 |
-
|
42 |
image = pipe(
|
43 |
-
prompt=prompt
|
44 |
-
negative_prompt=negative_prompt,
|
45 |
-
guidance_scale=guidance_scale,
|
46 |
-
num_inference_steps=num_inference_steps,
|
47 |
-
width=width,
|
48 |
-
height=height,
|
49 |
-
generator=generator,
|
50 |
).images[0]
|
51 |
|
52 |
-
return image
|
53 |
-
|
54 |
|
55 |
-
examples = [
|
56 |
-
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
57 |
-
"An astronaut riding a green horse",
|
58 |
-
"A delicious ceviche cheesecake slice",
|
59 |
-
]
|
60 |
|
61 |
css = """
|
62 |
#col-container {
|
@@ -82,73 +42,13 @@ with gr.Blocks(css=css) as demo:
|
|
82 |
|
83 |
result = gr.Image(label="Result", show_label=False)
|
84 |
|
85 |
-
with gr.Accordion("Advanced Settings", open=False):
|
86 |
-
negative_prompt = gr.Text(
|
87 |
-
label="Negative prompt",
|
88 |
-
max_lines=1,
|
89 |
-
placeholder="Enter a negative prompt",
|
90 |
-
visible=False,
|
91 |
-
)
|
92 |
-
|
93 |
-
seed = gr.Slider(
|
94 |
-
label="Seed",
|
95 |
-
minimum=0,
|
96 |
-
maximum=MAX_SEED,
|
97 |
-
step=1,
|
98 |
-
value=0,
|
99 |
-
)
|
100 |
-
|
101 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
102 |
-
|
103 |
-
with gr.Row():
|
104 |
-
width = gr.Slider(
|
105 |
-
label="Width",
|
106 |
-
minimum=16,
|
107 |
-
maximum=MAX_IMAGE_SIZE,
|
108 |
-
step=16,
|
109 |
-
value=256, # Replace with defaults that work for your model
|
110 |
-
)
|
111 |
-
|
112 |
-
height = gr.Slider(
|
113 |
-
label="Height",
|
114 |
-
minimum=16,
|
115 |
-
maximum=MAX_IMAGE_SIZE,
|
116 |
-
step=16,
|
117 |
-
value=256, # Replace with defaults that work for your model
|
118 |
-
)
|
119 |
-
|
120 |
-
with gr.Row():
|
121 |
-
guidance_scale = gr.Slider(
|
122 |
-
label="Guidance scale",
|
123 |
-
minimum=0.0,
|
124 |
-
maximum=10.0,
|
125 |
-
step=0.1,
|
126 |
-
value=0.0, # Replace with defaults that work for your model
|
127 |
-
)
|
128 |
-
|
129 |
-
num_inference_steps = gr.Slider(
|
130 |
-
label="Number of inference steps",
|
131 |
-
minimum=1,
|
132 |
-
maximum=50,
|
133 |
-
step=1,
|
134 |
-
value=2, # Replace with defaults that work for your model
|
135 |
-
)
|
136 |
-
|
137 |
-
gr.Examples(examples=examples, inputs=[prompt])
|
138 |
gr.on(
|
139 |
triggers=[run_button.click, prompt.submit],
|
140 |
fn=infer,
|
141 |
inputs=[
|
142 |
-
prompt
|
143 |
-
negative_prompt,
|
144 |
-
seed,
|
145 |
-
randomize_seed,
|
146 |
-
width,
|
147 |
-
height,
|
148 |
-
guidance_scale,
|
149 |
-
num_inference_steps,
|
150 |
],
|
151 |
-
outputs=[result
|
152 |
)
|
153 |
|
154 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
from diffusers import DiffusionPipeline
|
|
|
3 |
|
|
|
4 |
model_repo_id = "runwayml/stable-diffusion-v1-5" # Replace to the model you would like to use
|
5 |
|
6 |
+
pipe = DiffusionPipeline.from_pretrained(model_repo_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
pipe.load_lora_weights("OVAWARE/plixel-minecraft")
|
8 |
|
|
|
|
|
|
|
9 |
|
10 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
11 |
def infer(
|
12 |
+
prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
):
|
|
|
|
|
|
|
|
|
|
|
14 |
image = pipe(
|
15 |
+
prompt=prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
).images[0]
|
17 |
|
18 |
+
return image
|
|
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
css = """
|
22 |
#col-container {
|
|
|
42 |
|
43 |
result = gr.Image(label="Result", show_label=False)
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
gr.on(
|
46 |
triggers=[run_button.click, prompt.submit],
|
47 |
fn=infer,
|
48 |
inputs=[
|
49 |
+
prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
],
|
51 |
+
outputs=[result],
|
52 |
)
|
53 |
|
54 |
if __name__ == "__main__":
|