Spaces:
Running
on
Zero
Running
on
Zero
Kohaku-Blueleaf
commited on
Commit
•
4af557d
1
Parent(s):
32aef8c
updates UI and defaults
Browse files
app.py
CHANGED
@@ -199,10 +199,12 @@ def numpy2pytorch(imgs):
|
|
199 |
return h
|
200 |
|
201 |
|
202 |
-
@
|
203 |
def interrogator_process(x):
|
204 |
img = Image.fromarray(x)
|
205 |
-
rating, features, chars = get_wd14_tags(
|
|
|
|
|
206 |
result = ""
|
207 |
for char in chars:
|
208 |
result += char
|
@@ -211,7 +213,7 @@ def interrogator_process(x):
|
|
211 |
result += feature
|
212 |
result += ", "
|
213 |
result += max(rating, key=rating.get)
|
214 |
-
return result
|
215 |
|
216 |
|
217 |
@spaces.GPU
|
@@ -312,39 +314,45 @@ with block:
|
|
312 |
sources=["upload"], type="numpy", label="Image", height=384
|
313 |
)
|
314 |
with gr.Row():
|
315 |
-
with gr.Column(scale=
|
316 |
prompt = gr.Textbox(label="Output Prompt", interactive=True)
|
317 |
-
with gr.Column(scale=1, variant="compact", min_width=160):
|
318 |
n_prompt = gr.Textbox(
|
319 |
label="Negative Prompt",
|
320 |
value="lowres, worst quality, bad anatomy, bad hands, text, extra digit, fewer digits, cropped, low quality, jpeg artifacts, signature, watermark, username",
|
321 |
)
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
)
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
347 |
with gr.Column():
|
|
|
348 |
gr.Markdown("#### Sketch Outputs")
|
349 |
result_gallery = gr.Gallery(
|
350 |
height=384, object_fit="contain", label="Sketch Outputs", columns=4
|
@@ -358,11 +366,22 @@ with block:
|
|
358 |
|
359 |
input_fg.change(
|
360 |
lambda x: [
|
361 |
-
interrogator_process(x) if x is not None else "",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
gr.update(interactive=True),
|
363 |
],
|
364 |
inputs=[input_fg],
|
365 |
-
outputs=[prompt, key_gen_button],
|
|
|
|
|
|
|
366 |
)
|
367 |
|
368 |
key_gen_button.click(
|
|
|
199 |
return h
|
200 |
|
201 |
|
202 |
+
@spaces.GPU
|
203 |
def interrogator_process(x):
|
204 |
img = Image.fromarray(x)
|
205 |
+
rating, features, chars = get_wd14_tags(
|
206 |
+
img, general_threshold=0.3, character_threshold=0.75, no_underline=True
|
207 |
+
)
|
208 |
result = ""
|
209 |
for char in chars:
|
210 |
result += char
|
|
|
213 |
result += feature
|
214 |
result += ", "
|
215 |
result += max(rating, key=rating.get)
|
216 |
+
return result, f"{len(tokenizer.tokenize(result))}"
|
217 |
|
218 |
|
219 |
@spaces.GPU
|
|
|
314 |
sources=["upload"], type="numpy", label="Image", height=384
|
315 |
)
|
316 |
with gr.Row():
|
317 |
+
with gr.Column(scale=5):
|
318 |
prompt = gr.Textbox(label="Output Prompt", interactive=True)
|
|
|
319 |
n_prompt = gr.Textbox(
|
320 |
label="Negative Prompt",
|
321 |
value="lowres, worst quality, bad anatomy, bad hands, text, extra digit, fewer digits, cropped, low quality, jpeg artifacts, signature, watermark, username",
|
322 |
)
|
323 |
+
input_undo_steps = gr.Dropdown(
|
324 |
+
label="Operation Steps",
|
325 |
+
value=[900, 925, 950, 975],
|
326 |
+
choices=list(range(0, 1000, 5)),
|
327 |
+
multiselect=True,
|
328 |
+
)
|
329 |
+
num_sets = gr.Slider(
|
330 |
+
label="Num Sets", minimum=1, maximum=10, value=3, step=1
|
331 |
+
)
|
332 |
+
with gr.Column(scale=2, min_width=160):
|
333 |
+
token_counter = gr.Textbox(
|
334 |
+
label="Tokens Count", lines=1, interactive=False
|
335 |
+
)
|
336 |
+
recaption_button = gr.Button(value="Tagging", interactive=True)
|
337 |
+
seed = gr.Slider(
|
338 |
+
label="Seed", minimum=0, maximum=50000, step=1, value=37462
|
339 |
+
)
|
340 |
+
image_width = gr.Slider(
|
341 |
+
label="Target size",
|
342 |
+
minimum=512,
|
343 |
+
maximum=1024,
|
344 |
+
value=768,
|
345 |
+
step=32,
|
346 |
+
)
|
347 |
+
steps = gr.Slider(
|
348 |
+
label="Steps", minimum=1, maximum=32, value=16, step=1
|
349 |
+
)
|
350 |
+
cfg = gr.Slider(
|
351 |
+
label="CFG Scale", minimum=1.0, maximum=16, value=5, step=0.05
|
352 |
+
)
|
353 |
|
354 |
with gr.Column():
|
355 |
+
key_gen_button = gr.Button(value="Generate Sketch", interactive=False)
|
356 |
gr.Markdown("#### Sketch Outputs")
|
357 |
result_gallery = gr.Gallery(
|
358 |
height=384, object_fit="contain", label="Sketch Outputs", columns=4
|
|
|
366 |
|
367 |
input_fg.change(
|
368 |
lambda x: [
|
369 |
+
*(interrogator_process(x) if x is not None else ("", "")),
|
370 |
+
gr.update(interactive=True),
|
371 |
+
],
|
372 |
+
inputs=[input_fg],
|
373 |
+
outputs=[prompt, token_counter, key_gen_button],
|
374 |
+
)
|
375 |
+
recaption_button.click(
|
376 |
+
lambda x: [
|
377 |
+
*(interrogator_process(x) if x is not None else ("", "")),
|
378 |
gr.update(interactive=True),
|
379 |
],
|
380 |
inputs=[input_fg],
|
381 |
+
outputs=[prompt, token_counter, key_gen_button],
|
382 |
+
)
|
383 |
+
prompt.change(
|
384 |
+
lambda x: len(tokenizer.tokenize(x)), inputs=[prompt], outputs=[token_counter]
|
385 |
)
|
386 |
|
387 |
key_gen_button.click(
|