Merge 'nolialsea/patch-1' into settings without Colab changes

This commit is contained in:
Gnome Ann 2022-04-17 12:15:36 -04:00
commit c7b03398f6
2 changed files with 44 additions and 11 deletions

View File

@ -779,6 +779,7 @@ parser = argparse.ArgumentParser(description="KoboldAI Server")
parser.add_argument("--remote", action='store_true', help="Optimizes KoboldAI for Remote Play")
parser.add_argument("--ngrok", action='store_true', help="Optimizes KoboldAI for Remote Play using Ngrok")
parser.add_argument("--host", action='store_true', help="Optimizes KoboldAI for Remote Play without using a proxy service")
parser.add_argument("--port", type=int, help="Specify the port on which the application will be joinable")
parser.add_argument("--model", help="Specify the Model Type to skip the Menu")
parser.add_argument("--path", help="Specify the Path for local models (For model NeoCustom or GPT2Custom)")
parser.add_argument("--cpu", action='store_true', help="By default unattended launches are on the GPU use this option to force CPU usage.")
@ -5315,16 +5316,17 @@ def send_debug():
pass
emit('from_server', {'cmd': 'debug_info', 'data': debug_info}, broadcast=True)
#==================================================================#
# Final startup commands to launch Flask app
#==================================================================#
print("", end="", flush=True)
if __name__ == "__main__":
port = args.port if "port" in args and args.port is not None else 5000
print("{0}\nStarting webserver...{1}".format(colors.GREEN, colors.END), flush=True)
# Start Flask/SocketIO (Blocking, so this must be last method!)
#socketio.run(app, host='0.0.0.0', port=5000)
if(vars.host):
if(args.ngrok):
@ -5332,24 +5334,26 @@ if __name__ == "__main__":
cloudflare = _run_ngrok()
elif(args.remote):
from flask_cloudflared import _run_cloudflared
cloudflare = _run_cloudflared(5000)
cloudflare = _run_cloudflared(port)
if(args.ngrok or args.remote):
with open('cloudflare.log', 'w') as cloudflarelog:
cloudflarelog.write("KoboldAI has finished loading and is available at the following link : " + cloudflare)
print(format(colors.GREEN) + "KoboldAI has finished loading and is available at the following link : " + cloudflare + format(colors.END))
else:
print("{0}Webserver has started, you can now connect to this machine at port 5000{1}".format(colors.GREEN, colors.END))
print("{0}Webserver has started, you can now connect to this machine at port 5000{1}"
.format(colors.GREEN, colors.END))
vars.serverstarted = True
socketio.run(app, host='0.0.0.0', port=5000)
socketio.run(app, host='0.0.0.0', port=port)
else:
import webbrowser
webbrowser.open_new('http://localhost:5000')
print("{0}Server started!\nYou may now connect with a browser at http://127.0.0.1:5000/{1}".format(colors.GREEN, colors.END))
webbrowser.open_new('http://localhost:{0}'.format(port))
print("{0}Server started!\nYou may now connect with a browser at http://127.0.0.1:{1}/{2}"
.format(colors.GREEN, port, colors.END))
vars.serverstarted = True
if args.unblock:
socketio.run(app, port=5000, host='0.0.0.0')
socketio.run(app, port=port, host='0.0.0.0')
else:
socketio.run(app, port=5000)
socketio.run(app, port=port)
else:
print("{0}\nServer started in WSGI mode!{1}".format(colors.GREEN, colors.END), flush=True)

View File

@ -118,10 +118,33 @@ var adventure = false;
// Chatmode
var chatmode = false;
var sliders_throttle = getThrottle(200);
//=================================================================//
// METHODS
//=================================================================//
/**
* Returns a function that will automatically wait for X ms before executing the callback
* The timer is reset each time the returned function is called
* Useful for methods where something is overridden too fast
* @param ms milliseconds to wait before executing the callback
* @return {(function(*): void)|*} function that takes the ms to wait and a callback to execute after the timer
*/
function getThrottle(ms) {
var timer = {};
return function (id, callback) {
if (timer[id]) {
clearTimeout(timer[id]);
}
timer[id] = setTimeout(function () {
callback();
delete timer[id];
}, ms);
}
}
function addSetting(ob) {
// Add setting block to Settings Menu
if(ob.uitype == "slider"){
@ -153,8 +176,14 @@ function addSetting(ob) {
window["label_"+ob.id] = reflb; // Is this still needed?
// Add event function to input
refin.on("input", function () {
socket.send({'cmd': $(this).attr('id'), 'data': $(this).val()});
});
var that = this;
sliders_throttle(ob.id, function () {
socket.send({'cmd': $(that).attr('id'), 'data': $(that).val()});
refin.val(parseFloat($(that).val()));
reflb.html($(that).val());
});
}
);
} else if(ob.uitype == "toggle"){
settings_menu.append("<div class=\"settingitem\">\
<input type=\"checkbox\" data-toggle=\"toggle\" data-onstyle=\"success\" id=\""+ob.id+"\">\