Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,154 +1,76 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
from diffusers import DiffusionPipeline
|
7 |
-
import torch
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
|
13 |
-
torch_dtype = torch.float16
|
14 |
-
else:
|
15 |
-
torch_dtype = torch.float32
|
16 |
|
17 |
-
|
18 |
-
pipe = pipe.to(device)
|
19 |
-
|
20 |
-
MAX_SEED = np.iinfo(np.int32).max
|
21 |
-
MAX_IMAGE_SIZE = 1024
|
22 |
-
|
23 |
-
|
24 |
-
# @spaces.GPU #[uncomment to use ZeroGPU]
|
25 |
-
def infer(
|
26 |
-
prompt,
|
27 |
-
negative_prompt,
|
28 |
-
seed,
|
29 |
-
randomize_seed,
|
30 |
-
width,
|
31 |
-
height,
|
32 |
-
guidance_scale,
|
33 |
-
num_inference_steps,
|
34 |
-
progress=gr.Progress(track_tqdm=True),
|
35 |
-
):
|
36 |
-
if randomize_seed:
|
37 |
-
seed = random.randint(0, MAX_SEED)
|
38 |
-
|
39 |
-
generator = torch.Generator().manual_seed(seed)
|
40 |
|
|
|
41 |
image = pipe(
|
42 |
prompt=prompt,
|
43 |
negative_prompt=negative_prompt,
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
).images[0]
|
50 |
-
|
51 |
-
return image, seed
|
52 |
-
|
53 |
|
54 |
examples = [
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"A
|
|
|
58 |
]
|
59 |
|
60 |
css = """
|
61 |
#col-container {
|
62 |
margin: 0 auto;
|
63 |
-
max-width:
|
64 |
}
|
65 |
"""
|
66 |
|
|
|
|
|
67 |
with gr.Blocks(css=css) as demo:
|
68 |
with gr.Column(elem_id="col-container"):
|
69 |
-
gr.Markdown("
|
70 |
-
|
|
|
|
|
|
|
71 |
with gr.Row():
|
72 |
-
|
73 |
label="Prompt",
|
74 |
show_label=False,
|
75 |
max_lines=1,
|
76 |
placeholder="Enter your prompt",
|
77 |
container=False,
|
78 |
-
)
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
result = gr.Image(label="Result", show_label=False)
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
)
|
91 |
-
|
92 |
-
seed = gr.Slider(
|
93 |
-
label="Seed",
|
94 |
-
minimum=0,
|
95 |
-
maximum=MAX_SEED,
|
96 |
-
step=1,
|
97 |
-
value=0,
|
98 |
-
)
|
99 |
-
|
100 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
101 |
-
|
102 |
-
with gr.Row():
|
103 |
-
width = gr.Slider(
|
104 |
-
label="Width",
|
105 |
-
minimum=256,
|
106 |
-
maximum=MAX_IMAGE_SIZE,
|
107 |
-
step=32,
|
108 |
-
value=1024, # Replace with defaults that work for your model
|
109 |
-
)
|
110 |
|
111 |
-
|
112 |
-
label="Height",
|
113 |
-
minimum=256,
|
114 |
-
maximum=MAX_IMAGE_SIZE,
|
115 |
-
step=32,
|
116 |
-
value=1024, # Replace with defaults that work for your model
|
117 |
-
)
|
118 |
-
|
119 |
-
with gr.Row():
|
120 |
-
guidance_scale = gr.Slider(
|
121 |
-
label="Guidance scale",
|
122 |
-
minimum=0.0,
|
123 |
-
maximum=10.0,
|
124 |
-
step=0.1,
|
125 |
-
value=0.0, # Replace with defaults that work for your model
|
126 |
-
)
|
127 |
-
|
128 |
-
num_inference_steps = gr.Slider(
|
129 |
-
label="Number of inference steps",
|
130 |
-
minimum=1,
|
131 |
-
maximum=50,
|
132 |
-
step=1,
|
133 |
-
value=2, # Replace with defaults that work for your model
|
134 |
-
)
|
135 |
-
|
136 |
-
gr.Examples(examples=examples, inputs=[prompt])
|
137 |
-
gr.on(
|
138 |
-
triggers=[run_button.click, prompt.submit],
|
139 |
fn=infer,
|
140 |
-
inputs=[
|
141 |
-
|
142 |
-
negative_prompt,
|
143 |
-
seed,
|
144 |
-
randomize_seed,
|
145 |
-
width,
|
146 |
-
height,
|
147 |
-
guidance_scale,
|
148 |
-
num_inference_steps,
|
149 |
-
],
|
150 |
-
outputs=[result, seed],
|
151 |
)
|
152 |
|
153 |
-
|
154 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import openvino.runtime as ov
|
3 |
+
from optimum.intel.openvino import OVStableDiffusionPipeline
|
4 |
|
5 |
+
model_id = "HelloSun/chilloutmix_NiPrunedFp32Fix-openvino"
|
|
|
|
|
6 |
|
7 |
+
# 確保這些是有效的尺寸
|
8 |
+
HIGH = 512
|
9 |
+
WIDTH = 512
|
10 |
|
11 |
+
pipe = OVStableDiffusionPipeline.from_pretrained(model_id)
|
|
|
|
|
|
|
12 |
|
13 |
+
negative_prompt = "(worst quality, low quality, lowres), zombie, interlocked fingers,"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
def infer(prompt, negative_prompt):
|
16 |
image = pipe(
|
17 |
prompt=prompt,
|
18 |
negative_prompt=negative_prompt,
|
19 |
+
width=WIDTH, # 使用 WIDTH
|
20 |
+
height=HIGH, # 使用 HIGH
|
21 |
+
guidance_scale=7.5,
|
22 |
+
num_inference_steps=30,
|
23 |
+
num_images_per_prompt=1,
|
24 |
).images[0]
|
25 |
+
return image
|
|
|
|
|
26 |
|
27 |
examples = [
|
28 |
+
"Sailor Chibi Moon, Katsura Masakazu style",
|
29 |
+
"1girl, silver hair, symbol-shaped pupils, yellow eyes, smiling, light particles, light rays, wallpaper, star guardian, serious face, red inner hair, power aura, grandmaster1, golden and white clothes",
|
30 |
+
"A cute kitten, Tinkle style.",
|
31 |
+
"(illustration, 8k CG, extremely detailed),(whimsical),catgirl,teenage girl,playing in the snow,winter wonderland,snow-covered trees,soft pastel colors,gentle lighting,sparkling snow,joyful,magical atmosphere,highly detailed,fluffy cat ears and tail,intricate winter clothing,shallow depth of field,watercolor techniques,close-up shot,slightly tilted angle,fairy tale architecture,nostalgic,playful,winter magic,(masterpiece:2),best quality,ultra highres,original,extremely detailed,perfect lighting,",
|
32 |
]
|
33 |
|
34 |
css = """
|
35 |
#col-container {
|
36 |
margin: 0 auto;
|
37 |
+
max-width: 520px;
|
38 |
}
|
39 |
"""
|
40 |
|
41 |
+
power_device = "CPU"
|
42 |
+
|
43 |
with gr.Blocks(css=css) as demo:
|
44 |
with gr.Column(elem_id="col-container"):
|
45 |
+
gr.Markdown(f"""
|
46 |
+
# Disty0/SoteMixV3 {HIGH}x{WIDTH}
|
47 |
+
Currently running on {power_device}.
|
48 |
+
""")
|
49 |
+
|
50 |
with gr.Row():
|
51 |
+
prompt_input = gr.Text(
|
52 |
label="Prompt",
|
53 |
show_label=False,
|
54 |
max_lines=1,
|
55 |
placeholder="Enter your prompt",
|
56 |
container=False,
|
57 |
+
)
|
58 |
+
run_button = gr.Button("Run", scale=0)
|
59 |
+
|
|
|
60 |
result = gr.Image(label="Result", show_label=False)
|
61 |
|
62 |
+
gr.Examples(
|
63 |
+
examples=examples,
|
64 |
+
fn=infer,
|
65 |
+
inputs=[prompt_input],
|
66 |
+
outputs=[result]
|
67 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
+
run_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
fn=infer,
|
71 |
+
inputs=[prompt_input],
|
72 |
+
outputs=[result]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
)
|
74 |
|
75 |
+
demo.queue().launch()
|
76 |
+
|