Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -50,9 +50,6 @@ pipe = StableDiffusionXLPipeline(
|
|
50 |
force_zeros_for_empty_prompt=False
|
51 |
).to(device)
|
52 |
|
53 |
-
#pipe = pipe.to(device)
|
54 |
-
#pipe.enable_model_cpu_offload()
|
55 |
-
|
56 |
if hasattr(pipe.unet, 'encoder_hid_proj'):
|
57 |
pipe.unet.text_encoder_hid_proj = pipe.unet.encoder_hid_proj
|
58 |
|
@@ -61,8 +58,33 @@ pipe.load_ip_adapter(f'{root_dir}/weights/Kolors-IP-Adapter-Plus', subfolder="",
|
|
61 |
MAX_SEED = np.iinfo(np.int32).max
|
62 |
MAX_IMAGE_SIZE = 1024
|
63 |
|
|
|
|
|
|
|
64 |
@spaces.GPU(duration=80)
|
65 |
-
def infer(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
if randomize_seed:
|
67 |
seed = random.randint(0, MAX_SEED)
|
68 |
|
@@ -87,13 +109,29 @@ def infer(prompt, ip_adapter_image, ip_adapter_scale=0.5, negative_prompt="", se
|
|
87 |
return image, seed
|
88 |
|
89 |
examples = [
|
90 |
-
[
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
]
|
95 |
|
96 |
-
css="""
|
97 |
#col-container {
|
98 |
margin: 0 auto;
|
99 |
max-width: 720px;
|
@@ -105,6 +143,7 @@ css="""
|
|
105 |
height: 100%
|
106 |
}
|
107 |
"""
|
|
|
108 |
with gr.Blocks(css=css) as demo:
|
109 |
with gr.Column(elem_id="col-container"):
|
110 |
gr.Markdown(f"""
|
@@ -138,7 +177,13 @@ with gr.Blocks(css=css) as demo:
|
|
138 |
negative_prompt = gr.Text(
|
139 |
label="Negative prompt",
|
140 |
max_lines=1,
|
141 |
-
placeholder=
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
)
|
143 |
seed = gr.Slider(
|
144 |
label="Seed",
|
@@ -179,7 +224,6 @@ with gr.Blocks(css=css) as demo:
|
|
179 |
value=50,
|
180 |
)
|
181 |
|
182 |
-
|
183 |
gr.Examples(
|
184 |
examples=examples,
|
185 |
fn=infer,
|
@@ -191,8 +235,19 @@ with gr.Blocks(css=css) as demo:
|
|
191 |
gr.on(
|
192 |
triggers=[run_button.click, prompt.submit],
|
193 |
fn=infer,
|
194 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
outputs=[result, seed]
|
196 |
)
|
197 |
|
198 |
-
demo.queue().launch()
|
|
|
50 |
force_zeros_for_empty_prompt=False
|
51 |
).to(device)
|
52 |
|
|
|
|
|
|
|
53 |
if hasattr(pipe.unet, 'encoder_hid_proj'):
|
54 |
pipe.unet.text_encoder_hid_proj = pipe.unet.encoder_hid_proj
|
55 |
|
|
|
58 |
MAX_SEED = np.iinfo(np.int32).max
|
59 |
MAX_IMAGE_SIZE = 1024
|
60 |
|
61 |
+
# ----------------------------------------------
|
62 |
+
# ์์ ๋ ๋ถ๋ถ: infer ํจ์ ๋ด์์ hidden_prompt๋ฅผ ์์ ์ถ๊ฐ
|
63 |
+
# ----------------------------------------------
|
64 |
@spaces.GPU(duration=80)
|
65 |
+
def infer(
|
66 |
+
user_prompt,
|
67 |
+
ip_adapter_image,
|
68 |
+
ip_adapter_scale=0.5,
|
69 |
+
negative_prompt="",
|
70 |
+
seed=100,
|
71 |
+
randomize_seed=False,
|
72 |
+
width=1024,
|
73 |
+
height=1024,
|
74 |
+
guidance_scale=5.0,
|
75 |
+
num_inference_steps=50,
|
76 |
+
progress=gr.Progress(track_tqdm=True)
|
77 |
+
):
|
78 |
+
# ์จ๊ฒจ์ง(๊ธฐ๋ณธ/ํ์) ํ๋กฌํํธ
|
79 |
+
hidden_prompt = (
|
80 |
+
"Studio Ghibli animation style, featuring whimsical characters with expressive eyes "
|
81 |
+
"and fluid movements. Lush, detailed natural environments with ethereal lighting "
|
82 |
+
"and soft color palettes of blues, greens, and warm earth tones."
|
83 |
+
)
|
84 |
+
|
85 |
+
# ์ค์ ๋ก ํ์ดํ๋ผ์ธ์ ์ ๋ฌํ ์ต์ข
ํ๋กฌํํธ
|
86 |
+
prompt = f"{hidden_prompt}, {user_prompt}"
|
87 |
+
|
88 |
if randomize_seed:
|
89 |
seed = random.randint(0, MAX_SEED)
|
90 |
|
|
|
109 |
return image, seed
|
110 |
|
111 |
examples = [
|
112 |
+
[
|
113 |
+
"Studio Ghibli animation style, featuring whimsical characters with expressive eyes and fluid movements. Lush, detailed natural environments with ethereal lighting and soft color palettes of blues, greens, and warm earth tones. \"aged baby\"",
|
114 |
+
"gh1.jpg",
|
115 |
+
0.5
|
116 |
+
],
|
117 |
+
[
|
118 |
+
"Studio Ghibli animation style, featuring whimsical characters with expressive eyes and fluid movements. Lush, detailed natural environments with ethereal lighting and soft color palettes of blues, greens, and warm earth tones. \"aged baby\"",
|
119 |
+
"gh2.jpg",
|
120 |
+
0.5
|
121 |
+
],
|
122 |
+
[
|
123 |
+
"Studio Ghibli animation style, featuring whimsical characters with expressive eyes and fluid movements. Lush, detailed natural environments with ethereal lighting and soft color palettes of blues, greens, and warm earth tones. \"aged baby\"",
|
124 |
+
"gh3.webp",
|
125 |
+
0.5
|
126 |
+
],
|
127 |
+
[
|
128 |
+
"Studio Ghibli animation style, featuring whimsical characters with expressive eyes and fluid movements. Lush, detailed natural environments with ethereal lighting and soft color palettes of blues, greens, and warm earth tones. \"aged baby\"",
|
129 |
+
"gh4.webp",
|
130 |
+
0.5
|
131 |
+
],
|
132 |
]
|
133 |
|
134 |
+
css = """
|
135 |
#col-container {
|
136 |
margin: 0 auto;
|
137 |
max-width: 720px;
|
|
|
143 |
height: 100%
|
144 |
}
|
145 |
"""
|
146 |
+
|
147 |
with gr.Blocks(css=css) as demo:
|
148 |
with gr.Column(elem_id="col-container"):
|
149 |
gr.Markdown(f"""
|
|
|
177 |
negative_prompt = gr.Text(
|
178 |
label="Negative prompt",
|
179 |
max_lines=1,
|
180 |
+
placeholder=(
|
181 |
+
"Copy(worst quality, low quality:1.4), bad anatomy, bad hands, text, error, "
|
182 |
+
"missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, "
|
183 |
+
"normal quality, jpeg artifacts, signature, watermark, username, blurry, "
|
184 |
+
"artist name, (deformed iris, deformed pupils:1.2), (semi-realistic, cgi, "
|
185 |
+
"3d, render:1.1), amateur, (poorly drawn hands, poorly drawn face:1.2)"
|
186 |
+
),
|
187 |
)
|
188 |
seed = gr.Slider(
|
189 |
label="Seed",
|
|
|
224 |
value=50,
|
225 |
)
|
226 |
|
|
|
227 |
gr.Examples(
|
228 |
examples=examples,
|
229 |
fn=infer,
|
|
|
235 |
gr.on(
|
236 |
triggers=[run_button.click, prompt.submit],
|
237 |
fn=infer,
|
238 |
+
inputs=[
|
239 |
+
prompt,
|
240 |
+
ip_adapter_image,
|
241 |
+
ip_adapter_scale,
|
242 |
+
negative_prompt,
|
243 |
+
seed,
|
244 |
+
randomize_seed,
|
245 |
+
width,
|
246 |
+
height,
|
247 |
+
guidance_scale,
|
248 |
+
num_inference_steps
|
249 |
+
],
|
250 |
outputs=[result, seed]
|
251 |
)
|
252 |
|
253 |
+
demo.queue().launch()
|