Spaces:
Running
on
Zero
Running
on
Zero
votepurchase
commited on
Commit
•
3f7be09
1
Parent(s):
3d8ea71
Update app.py
Browse files
app.py
CHANGED
@@ -1,131 +1,3 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
import PIL.Image
|
4 |
-
from PIL import Image
|
5 |
-
import random
|
6 |
-
from diffusers import ControlNetModel, StableDiffusionXLPipeline, AutoencoderKL
|
7 |
-
from diffusers import DDIMScheduler, EulerAncestralDiscreteScheduler
|
8 |
-
import cv2
|
9 |
-
import torch
|
10 |
-
import spaces
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
15 |
-
|
16 |
-
pipe = StableDiffusionXLPipeline.from_pretrained(
|
17 |
-
"votepurchase/animagine-xl-3.1",
|
18 |
-
vae=vae,
|
19 |
-
torch_dtype=torch.float16,
|
20 |
-
)
|
21 |
-
|
22 |
-
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
23 |
-
pipe.to(device)
|
24 |
-
|
25 |
-
MAX_SEED = np.iinfo(np.int32).max
|
26 |
-
MAX_IMAGE_SIZE = 1216
|
27 |
-
|
28 |
-
|
29 |
-
@spaces.GPU
|
30 |
-
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
31 |
-
|
32 |
-
if randomize_seed:
|
33 |
-
seed = random.randint(0, MAX_SEED)
|
34 |
-
|
35 |
-
generator = torch.Generator().manual_seed(seed)
|
36 |
-
|
37 |
-
output_image = pipe(
|
38 |
-
prompt=prompt,
|
39 |
-
negative_prompt=negative_prompt,
|
40 |
-
guidance_scale=guidance_scale,
|
41 |
-
num_inference_steps=num_inference_steps,
|
42 |
-
width=width,
|
43 |
-
height=height,
|
44 |
-
generator=generator
|
45 |
-
).images[0]
|
46 |
-
|
47 |
-
return output_image
|
48 |
-
|
49 |
-
|
50 |
-
css = """
|
51 |
-
#col-container {
|
52 |
-
margin: 0 auto;
|
53 |
-
max-width: 520px;
|
54 |
-
}
|
55 |
-
"""
|
56 |
-
|
57 |
-
with gr.Blocks(css=css) as demo:
|
58 |
-
|
59 |
-
with gr.Column(elem_id="col-container"):
|
60 |
-
|
61 |
-
with gr.Row():
|
62 |
-
prompt = gr.Text(
|
63 |
-
label="Prompt",
|
64 |
-
show_label=False,
|
65 |
-
max_lines=1,
|
66 |
-
placeholder="Enter your prompt",
|
67 |
-
container=False,
|
68 |
-
)
|
69 |
-
|
70 |
-
run_button = gr.Button("Run", scale=0)
|
71 |
-
|
72 |
-
result = gr.Image(label="Result", show_label=False)
|
73 |
-
|
74 |
-
with gr.Accordion("Advanced Settings", open=False):
|
75 |
-
|
76 |
-
negative_prompt = gr.Text(
|
77 |
-
label="Negative prompt",
|
78 |
-
max_lines=1,
|
79 |
-
placeholder="Enter a negative prompt",
|
80 |
-
value="nsfw, (low quality, worst quality:1.2), very displeasing, 3d, watermark, signature, ugly, poorly drawn"
|
81 |
-
)
|
82 |
-
|
83 |
-
seed = gr.Slider(
|
84 |
-
label="Seed",
|
85 |
-
minimum=0,
|
86 |
-
maximum=MAX_SEED,
|
87 |
-
step=1,
|
88 |
-
value=0,
|
89 |
-
)
|
90 |
-
|
91 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
92 |
-
|
93 |
-
with gr.Row():
|
94 |
-
width = gr.Slider(
|
95 |
-
label="Width",
|
96 |
-
minimum=256,
|
97 |
-
maximum=MAX_IMAGE_SIZE,
|
98 |
-
step=32,
|
99 |
-
value=1024,#832,
|
100 |
-
)
|
101 |
-
|
102 |
-
height = gr.Slider(
|
103 |
-
label="Height",
|
104 |
-
minimum=256,
|
105 |
-
maximum=MAX_IMAGE_SIZE,
|
106 |
-
step=32,
|
107 |
-
value=1024,#1216,
|
108 |
-
)
|
109 |
-
|
110 |
-
with gr.Row():
|
111 |
-
guidance_scale = gr.Slider(
|
112 |
-
label="Guidance scale",
|
113 |
-
minimum=0.0,
|
114 |
-
maximum=20.0,
|
115 |
-
step=0.1,
|
116 |
-
value=7,
|
117 |
-
)
|
118 |
-
|
119 |
-
num_inference_steps = gr.Slider(
|
120 |
-
label="Number of inference steps",
|
121 |
-
minimum=1,
|
122 |
-
maximum=28,
|
123 |
-
step=1,
|
124 |
-
value=28,
|
125 |
-
)
|
126 |
-
|
127 |
-
run_button.click(#lambda x: None, inputs=None, outputs=result).then(
|
128 |
-
fn=infer,
|
129 |
-
inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
130 |
-
outputs=[result]
|
131 |
-
)
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
gr.load("models/votepurchase/animagine-xl-3.1").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|