Skip to content

Commit

Permalink
removed unused import; now using javascript to watch prompt textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
liamkerr committed Sep 28, 2022
1 parent e5707b6 commit 7ca9858
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 11 additions & 9 deletions javascript/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,23 @@ onUiUpdate(function(){
});

json_elem.parentElement.style.display="none"

if (!txt2img_textarea) {
txt2img_textarea = gradioApp().querySelector("#txt2img_prompt > label > textarea");
txt2img_textarea?.addEventListener("input", () => update_token_counter("txt2img_token_button"));
}
if (!img2img_textarea) {
img2img_textarea = gradioApp().querySelector("#img2img_prompt > label > textarea");
img2img_textarea?.addEventListener("input", () => update_token_counter("img2img_token_button"));
}
})

let txt2img_textarea, img2img_textarea = undefined;
let wait_time = 800
let token_timeout;
function txt2img_token_counter(text) {
return update_token_counter("txt2img_token_button", text);
}

function img2img_token_counter(text) {
return update_token_counter("img2img_token_button", text);
}

function update_token_counter(button_id, text) {
function update_token_counter(button_id) {
if (token_timeout)
clearTimeout(token_timeout);
token_timeout = setTimeout(() => gradioApp().getElementById(button_id)?.click(), wait_time);
return [];
}
2 changes: 0 additions & 2 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import modules.shared as shared
from modules.sd_samplers import samplers, samplers_for_img2img
from modules.sd_hijack import model_hijack
from modules.helpers import debounce
import modules.ldsr_model
import modules.scripts
import modules.gfpgan_model
Expand Down Expand Up @@ -345,7 +344,6 @@ def create_toprow(is_img2img):
with gr.Column(scale=80):
with gr.Row():
prompt = gr.Textbox(label="Prompt", elem_id=f"{id_part}_prompt", show_label=False, placeholder="Prompt", lines=2)
prompt.change(fn=lambda *args: [], _js=f"{id_part}_token_counter", inputs=[prompt], outputs=[], preprocess=False)

with gr.Column(scale=1, elem_id="roll_col"):
roll = gr.Button(value=art_symbol, elem_id="roll", visible=len(shared.artist_db.artists) > 0)
Expand Down

0 comments on commit 7ca9858

Please sign in to comment.