From 6296d5b77358f5fd966fcd53332a39bf8a3fd337 Mon Sep 17 00:00:00 2001 From: krolhm Date: Sun, 16 Jul 2023 03:40:55 +0200 Subject: [PATCH] lock input when generating response --- app/.DS_Store | Bin 6148 -> 0 bytes app/run.py | 17 +++++----- app/static/js/script.js | 69 +++++++++++++++++++++++---------------- app/static/styles.css | 17 +++++++--- app/templates/index.html | 6 ++-- 5 files changed, 66 insertions(+), 43 deletions(-) delete mode 100644 app/.DS_Store diff --git a/app/.DS_Store b/app/.DS_Store deleted file mode 100644 index 147a7d9ef19e61c9e66fd5899caab8d03b0815fc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOHRWu5S=Nd6tU@&4U$h#i5rBfELd{^+7cn8KoFq|cHVOsjtFl)Ae>~45SoeX zXOG`ZoF~N}BI4El_MB)zL~|5Dmd1#Qdvs{xJU5`BjcTbPB1pD=eG9vfIfZHMC2IZc1C6~{7 z++(n6okOD$b)matfA2-08x{(L0--=C5DKUQ*t5mvCx%gn0--=C@U4KX4+%xEa?FOh zbfD5J0B{Po8rpLFl$hjLIc7tQz}P~87Rr9bU<-#oIj?feh89ljmk;(ge_dW!-;VrA z>BN;`)S*BqP%3a>-G%J`m-uByFZpFi^g@A9;GZeL)AjXwg^%*Rb?|wz*Cv!36fxmt oX~57f4gu)MI&!LmHlCynUgek#C5!kq92f@y6(p)q;1?A51P4V;%>V!Z diff --git a/app/run.py b/app/run.py index 8ec7620..da97970 100644 --- a/app/run.py +++ b/app/run.py @@ -31,7 +31,6 @@ ############################################################## PROCESS = None -CUSTOM = False MODEL_7B = "llama.cpp/models/WizardLM-7B-V1.0-Uncensored/ggml-model-q4_0.bin" MODEL_13B = "llama.cpp/models/WizardLM-13B-V1.0-Uncensored/ggml-model-q4_0.bin" MODEL_33B = "llama.cpp/models/WizardLM-33B-V1.0-Uncensored/ggml-model-q4_0.bin" @@ -41,6 +40,7 @@ output_queue = Queue() input_queue = Queue() is_generating_image = False # pylint: disable=invalid-name +custom = False # pylint: disable=invalid-name nlp = spacy.load("en_core_web_sm") @@ -67,9 +67,10 @@ pipe = pipe.to("cuda") pipe.enable_attention_slicing() # Recommended if your computer has < 64 GB of RAM -werkzeug_logger = logging.getLogger('werkzeug') +werkzeug_logger = logging.getLogger("werkzeug") werkzeug_logger.setLevel(logging.ERROR) + @app.route("/") def index(): """ @@ -91,10 +92,10 @@ def execute(): """ global system # pylint: disable=invalid-name, global-variable-not-assigned mode = request.form["mode"] - if (mode == "custom"): - CUSTOM = True + if mode == "custom": # pylint: disable=simplifiable-if-statement + custom = True # pylint: disable=redefined-outer-name else: - CUSTOM = False + custom = False model = "WizardLM-7B-V1.0-Uncensored" if os.path.exists(MODEL_13B) and not LIGHT_MODE: @@ -105,7 +106,7 @@ def execute(): command = "" if system == "Darwin": - if CUSTOM: + if custom: command = f'./llama.cpp/main -m llama.cpp/models/{model}/ggml-model-q4_0.bin \ -ngl 1 --repeat_penalty 1.1 --color --interactive-first \ -f app/prompts/CustomRolePlay.txt -r "USER: "' @@ -113,7 +114,7 @@ def execute(): command = f'./llama.cpp/main -m llama.cpp/models/{model}/ggml-model-q4_0.bin \ -ngl 1 --repeat_penalty 1.1 --color -i -f app/prompts/RolePlay.txt -r "USER: "' elif system == "Linux": - if CUSTOM: + if custom: command = f'./llama.cpp/main -m llama.cpp/models/{model}/ggml-model-q4_0.bin \ --repeat_penalty 1.1 --color --interactive-first \ -f app/prompts/RolePlay.txt -r "USER: "' @@ -169,7 +170,7 @@ def get_output(): try: output = output_queue.get(timeout=1.0) if "USER:" in output: - output = "" + output = "[EOS]" except Empty: output = "" return jsonify(output=output) diff --git a/app/static/js/script.js b/app/static/js/script.js index 84f9057..1eaffe1 100644 --- a/app/static/js/script.js +++ b/app/static/js/script.js @@ -3,21 +3,36 @@ var isRunning = false; var rpStarted = false; var modelLoading = 0; var prompt = ""; +var mode = ""; -function startExecution(mode) { +function startExecution() { if (isRunning) return; isRunning = true; $.post('/execute', {mode: mode} , function(data) { pollOutput(); }); - document.getElementById("start-button-random").remove(); - document.getElementById("start-button-custom").remove(); + document.getElementById("button-container").remove(); + $('#input-command').prop('disabled', true); + $('#input-command').val('Generating response...'); + $('#send-button').prop('disabled', true); + $('#send-button').val('🔒'); } function pollOutput() { $.get('/get_output', function(data) { var output = data.output; - if (output && rpStarted) { + if (!rpStarted) { + var progressBar = document.querySelector('.progress'); + modelLoading += 0.07; + progressBar.style.width = String(modelLoading) + '%'; + } + if (isRunning) { + setTimeout(pollOutput, pollingInterval); + } + if (output.includes("===")) { + rpStarted = true; + } + if (output && rpStarted && output !== "[EOS]") { prompt = prompt + output; if (prompt.length > 300) prompt = prompt.slice(output.length); @@ -29,35 +44,31 @@ function pollOutput() { progressBar.style.width = String(modelLoading) + '%'; } } - if (!rpStarted) { - var progressBar = document.querySelector('.progress'); - modelLoading += 0.07; - progressBar.style.width = String(modelLoading) + '%'; - } - if (isRunning) { - setTimeout(pollOutput, pollingInterval); - } - if (output.includes("===")) { - rpStarted = true; + if (output === "[EOS]" && rpStarted) { + $('#input-command').prop('disabled', false); + $('#input-command').val(''); + $('#send-button').prop('disabled', false); + $('#send-button').val('Send'); + $.post('/generate_image', { prompt: prompt }, function(data) { + if (data.error) + return; + var imageContainer = document.getElementById('image-container'); + var image = document.createElement('img'); + image.src = "/images/" + data.file_name; + imageContainer.innerHTML = ''; + imageContainer.appendChild(image); + }) } }); } - function sendInput() { var input = $('#input-command').val().trim(); - $('#input-command').val(''); + $('#input-command').val('Generating response...'); + $('#input-command').prop('disabled', true); + $('#send-button').prop('disabled', true); + $('#send-button').val('🔒'); $.post('/send_input', {input: input}); - - $.post('/generate_image', { prompt: prompt != "" ? prompt : input }, function(data) { - if (data.error) - return; - var imageContainer = document.getElementById('image-container'); - var image = document.createElement('img'); - image.src = "/images/" + data.file_name; - imageContainer.innerHTML = ''; - imageContainer.appendChild(image); - }) } function reloadPage() { @@ -76,13 +87,15 @@ $(document).ready(function() { $('#start-button-random').click(function() { $(this).hide(); $('#input-form').show(); - startExecution("random"); + mode = "random"; + startExecution(); }); $('#start-button-custom').click(function() { $(this).hide(); $('#input-form').show(); - startExecution("custom"); + mode = "custom"; + startExecution(); }); $('#input-form').submit(function(event) { diff --git a/app/static/styles.css b/app/static/styles.css index b70a6d8..648a183 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -57,13 +57,14 @@ body { overflow-wrap: break-word; } -#input-form, #download-form { - width: 100%; - text-align: center; +#input-form { + display: flex; + justify-content: center; + align-items: center; } #input-command { - width: 70%; + width: 400px; padding: 10px; border: none; border-radius: 25px; @@ -99,7 +100,7 @@ button { color: white; border-radius: 25px; cursor: pointer; - margin-bottom: 20px; + margin: 0 20px; } #reload-button { @@ -172,3 +173,9 @@ img { padding: 40px; width: 120%; } + +#button-container { + display: flex; + justify-content: center; + align-items: center; +} diff --git a/app/templates/index.html b/app/templates/index.html index 0e136d4..18cb243 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -16,8 +16,10 @@

📖 LLM RP

- - +
+ + +