openfree commited on
Commit
6d1b6ef
ยท
verified ยท
1 Parent(s): da4db7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -13
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(prompt, ip_adapter_image, ip_adapter_scale=0.5, negative_prompt="", seed=100, randomize_seed=False, width=1024, height=1024, guidance_scale=5.0, num_inference_steps=50, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- ["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"", "gh1.jpg", 0.5],
91
- ["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"", "gh2.jpg", 0.5],
92
- ["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"", "gh3.webp", 0.5],
93
- ["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"", "gh4.webp", 0.5],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="Copy(worst quality, low quality:1.4), bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name, (deformed iris, deformed pupils:1.2), (semi-realistic, cgi, 3d, render:1.1), amateur, (poorly drawn hands, poorly drawn face:1.2)",
 
 
 
 
 
 
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=[prompt, ip_adapter_image, ip_adapter_scale, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
 
 
 
 
 
 
 
 
 
 
 
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()