From 462206fa86104ba5ea98012ae30233900c5ba4bf Mon Sep 17 00:00:00 2001 From: ebolam Date: Tue, 14 Jun 2022 19:11:30 -0400 Subject: [PATCH] added --remote not allowing navigation outside of the model folder for custom models. added a delete custom models option (will not delete models outside of the models directory, nor will it delete non-model directories) --- aiserver.py | 20 +++++++++++++++-- pytest.ini | 2 +- static/application.js | 19 +++++++++++----- static/custom.css | 51 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 8 deletions(-) diff --git a/aiserver.py b/aiserver.py index 35b20613..be11305a 100644 --- a/aiserver.py +++ b/aiserver.py @@ -354,6 +354,7 @@ from flask import Flask, render_template, Response, request, copy_current_reques from flask_socketio import SocketIO, emit app = Flask(__name__, root_path=os.getcwd()) app.config['SECRET KEY'] = 'secret!' +app.config['TEMPLATES_AUTO_RELOAD'] = True socketio = SocketIO(app, async_method="eventlet") print("{0}OK!{1}".format(colors.GREEN, colors.END)) @@ -364,6 +365,8 @@ def sendModelSelection(menu="mainmenu", folder="./models"): #If we send one of the manual load options, send back the list of model directories, otherwise send the menu if menu in ('NeoCustom', 'GPT2Custom'): (paths, breadcrumbs) = get_folder_path_info(folder) + if args.remote: + breadcrumbs = [] menu_list = [[folder, menu, "", False] for folder in paths] menu_list.append(["Return to Main Menu", "mainmenu", "", True]) emit('from_server', {'cmd': 'show_model_menu', 'data': menu_list, 'menu': menu, 'breadcrumbs': breadcrumbs}, broadcast=True) @@ -2023,7 +2026,10 @@ def load_model(use_gpu=True, gpu_layers=None, initial_load=False, online_model=" @app.route('/') @app.route('/index') def index(): - return render_template('index.html', hide_ai_menu=args.noaimenu) + if 'new_ui' in request.args: + return render_template('index_new.html', hide_ai_menu=args.noaimenu) + else: + return render_template('index.html', hide_ai_menu=args.noaimenu) @app.route('/favicon.ico') def favicon(): return send_from_directory(app.root_path, @@ -3090,7 +3096,17 @@ def get_message(msg): get_model_info(msg['data'], directory=msg['path']) else: get_model_info(vars.model) - + elif(msg['cmd'] == 'delete_model'): + if "{}/models".format(os.getcwd()) in msg['data'] or "{}\\models".format(os.getcwd()) in msg['data']: + if check_if_dir_is_model(msg['data']): + print("It's a model, now we really will kill it") + import shutil + shutil.rmtree(msg['data']) + sendModelSelection(menu=msg['menu']) + else: + print("Not a model, don't delete") + else: + print("Ah ah ah, you didn't say the magic word: The selected directory is not in the KoboldAI Models directory, not doing anything.") elif(msg['cmd'] == 'OAI_Key_Update'): get_oai_models(msg['key']) elif(msg['cmd'] == 'loadselect'): diff --git a/pytest.ini b/pytest.ini index 7d88e841..c930ba37 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -addopts = --ignore=miniconda3 --html=unit_test_report.html --self-contained-html -v \ No newline at end of file +addopts = --ignore=miniconda3 --ignore=runtime --html=unit_test_report.html --self-contained-html -v \ No newline at end of file diff --git a/static/application.js b/static/application.js index 9470cee9..0692ac4a 100644 --- a/static/application.js +++ b/static/application.js @@ -1017,6 +1017,14 @@ function buildLoadModelList(ar, menu, breadcrumbs) { $("#loadmodellistbreadcrumbs").append("
") } for(i=0; i\
" @@ -1027,13 +1035,14 @@ function buildLoadModelList(ar, menu, breadcrumbs) { //this is a model html = html + "
" } - if (Array.isArray(ar[i][0])) { - full_path = ar[i][0][0]; - folder = ar[i][0][1]; + + //now let's do the delete icon if applicable + if (['NeoCustom', 'GPT2Custom'].includes(menu) && !ar[i][3]) { + html = html + "" } else { - full_path = ""; - folder = ar[i][0]; + html = html + "
" } + html = html + "
\
\
"+folder+"
\ diff --git a/static/custom.css b/static/custom.css index 078ae7d2..6a76f750 100644 --- a/static/custom.css +++ b/static/custom.css @@ -1474,4 +1474,55 @@ body.connected .popupfooter, .popupfooter.always-available { .model_layers:focus { color: #cdf; +} + +.menu_icon { + position: fixed; + top:10px; + left: 5px; + z-index:100; + display: inline-block; + cursor: pointer; +} + +.SideMenu { + height: 100%; + width: 0; + position: fixed; + z-index: 1; + top: 0; + left: 0; + background-color: #111; + overflow-x: hidden; + transition: 0.5s; + padding-top: 60px; +} + +.SideMenu.open { + width: 450px; +} + +@media only screen and (max-width: 768px) { + .SideMenu.open { + width: 100%; + } +} + + +.menubar1, .menubar2, .menubar3 { + width: 21px; + height: 3px; + background-color: #999; + margin: 3px 0; + transition: 0.4s; +} + +.change .menubar1 { + transform: translate(0px, 6px) rotate(-45deg); +} + +.change .menubar2 {opacity: 0;} + +.change .menubar3 { + transform: translate(0px, -6px) rotate(45deg); } \ No newline at end of file