mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Initial Load Story dialog
This commit is contained in:
60
aiserver.py
60
aiserver.py
@@ -5201,7 +5201,7 @@ def saveRequest(savpath, savepins=True):
|
|||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Show list of saved stories
|
# Show list of saved stories
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def getloadlist():
|
def getloadlist(data=None):
|
||||||
emit('from_server', {'cmd': 'buildload', 'data': fileops.getstoryfiles()}, room="UI_1")
|
emit('from_server', {'cmd': 'buildload', 'data': fileops.getstoryfiles()}, room="UI_1")
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
@@ -5869,11 +5869,6 @@ def ui2_connect():
|
|||||||
#==================================================================#
|
#==================================================================#
|
||||||
# File Popup options
|
# File Popup options
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
@app.route("/popup_test")
|
|
||||||
def popup_test():
|
|
||||||
file_popup("Test Popup", "./", "return_event_name", renameable=True, folder_only=False, editable=True, deleteable=True, jailed=False, item_check=check_if_dir_is_model)
|
|
||||||
return "ok"
|
|
||||||
|
|
||||||
@socketio.on('upload_file')
|
@socketio.on('upload_file')
|
||||||
def upload_file(data):
|
def upload_file(data):
|
||||||
print("upload_file {}".format(data['filename']))
|
print("upload_file {}".format(data['filename']))
|
||||||
@@ -5996,7 +5991,9 @@ def popup_change_file(data):
|
|||||||
else:
|
else:
|
||||||
print("User is trying to delete files in your server outside the jail. Blocked. Jailed Dir: {} Requested Dir: {}".format(session['popup_jailed_dir'], data))
|
print("User is trying to delete files in your server outside the jail. Blocked. Jailed Dir: {} Requested Dir: {}".format(session['popup_jailed_dir'], data))
|
||||||
|
|
||||||
def file_popup(popup_title, starting_folder, return_event, upload=True, jailed=True, folder_only=True, renameable=False, deleteable=False, editable=False, show_breadcrumbs=True, item_check=None, show_hidden=False):
|
def file_popup(popup_title, starting_folder, return_event, upload=True, jailed=True, folder_only=True, renameable=False, deleteable=False,
|
||||||
|
editable=False, show_breadcrumbs=True, item_check=None, show_hidden=False,
|
||||||
|
valid_only=False, hide_extention=False):
|
||||||
#starting_folder = The folder we're going to get folders and/or items from
|
#starting_folder = The folder we're going to get folders and/or items from
|
||||||
#return_event = the socketio event that will be emitted when the load button is clicked
|
#return_event = the socketio event that will be emitted when the load button is clicked
|
||||||
#jailed = if set to true will look for the session variable jailed_folder and prevent navigation outside of that folder
|
#jailed = if set to true will look for the session variable jailed_folder and prevent navigation outside of that folder
|
||||||
@@ -6006,6 +6003,8 @@ def file_popup(popup_title, starting_folder, return_event, upload=True, jailed=T
|
|||||||
#show_breadcrumbs = will show the breadcrumbs at the top of the screen
|
#show_breadcrumbs = will show the breadcrumbs at the top of the screen
|
||||||
#item_check will call this function to check if the item is valid as a selection if not none. Will pass absolute directory as only argument to function
|
#item_check will call this function to check if the item is valid as a selection if not none. Will pass absolute directory as only argument to function
|
||||||
#show_hidden = ... really, you have to ask?
|
#show_hidden = ... really, you have to ask?
|
||||||
|
#valid_only = only show valid files
|
||||||
|
#hide_extention = hide extensions
|
||||||
if jailed:
|
if jailed:
|
||||||
session['popup_jailed_dir'] = os.path.abspath(starting_folder).replace("\\", "/")
|
session['popup_jailed_dir'] = os.path.abspath(starting_folder).replace("\\", "/")
|
||||||
else:
|
else:
|
||||||
@@ -6018,6 +6017,8 @@ def file_popup(popup_title, starting_folder, return_event, upload=True, jailed=T
|
|||||||
session['popup_folder_only'] = folder_only
|
session['popup_folder_only'] = folder_only
|
||||||
session['popup_show_breadcrumbs'] = show_breadcrumbs
|
session['popup_show_breadcrumbs'] = show_breadcrumbs
|
||||||
session['upload'] = upload
|
session['upload'] = upload
|
||||||
|
session['valid_only'] = valid_only
|
||||||
|
session['hide_extention'] = hide_extention
|
||||||
|
|
||||||
socketio.emit("load_popup", {"popup_title": popup_title, "call_back": return_event, "renameable": renameable, "deleteable": deleteable, "editable": editable, 'upload': upload}, broadcast=True, room="UI_2")
|
socketio.emit("load_popup", {"popup_title": popup_title, "call_back": return_event, "renameable": renameable, "deleteable": deleteable, "editable": editable, 'upload': upload}, broadcast=True, room="UI_2")
|
||||||
socketio.emit("load_popup", {"popup_title": popup_title, "call_back": return_event, "renameable": renameable, "deleteable": deleteable, "editable": editable, 'upload': upload}, broadcast=True, room="UI_1")
|
socketio.emit("load_popup", {"popup_title": popup_title, "call_back": return_event, "renameable": renameable, "deleteable": deleteable, "editable": editable, 'upload': upload}, broadcast=True, room="UI_1")
|
||||||
@@ -6032,6 +6033,8 @@ def get_files_folders(starting_folder):
|
|||||||
show_breadcrumbs = session['popup_show_breadcrumbs']
|
show_breadcrumbs = session['popup_show_breadcrumbs']
|
||||||
show_hidden = session['popup_show_hidden']
|
show_hidden = session['popup_show_hidden']
|
||||||
folder_only = session['popup_folder_only']
|
folder_only = session['popup_folder_only']
|
||||||
|
valid_only = session['valid_only']
|
||||||
|
hide_extention = session['hide_extention']
|
||||||
|
|
||||||
if starting_folder == 'This PC':
|
if starting_folder == 'This PC':
|
||||||
breadcrumbs = [['This PC', 'This PC']]
|
breadcrumbs = [['This PC', 'This PC']]
|
||||||
@@ -6049,6 +6052,12 @@ def get_files_folders(starting_folder):
|
|||||||
else:
|
else:
|
||||||
if len([["{}:/".format(chr(i)), "{}:\\".format(chr(i))] for i in range(65, 91) if os.path.exists("{}:".format(chr(i)))]) > 0:
|
if len([["{}:/".format(chr(i)), "{}:\\".format(chr(i))] for i in range(65, 91) if os.path.exists("{}:".format(chr(i)))]) > 0:
|
||||||
breadcrumbs.insert(0, ['This PC', 'This PC'])
|
breadcrumbs.insert(0, ['This PC', 'This PC'])
|
||||||
|
|
||||||
|
#if we're jailed, remove the stuff before the jail from the breadcrumbs
|
||||||
|
if session['popup_jailed_dir'] is not None:
|
||||||
|
|
||||||
|
breadcrumbs = breadcrumbs[len(session['popup_jailed_dir'].split("/")):]
|
||||||
|
|
||||||
folders = []
|
folders = []
|
||||||
files = []
|
files = []
|
||||||
base_path = os.path.abspath(starting_folder).replace("\\", "/")
|
base_path = os.path.abspath(starting_folder).replace("\\", "/")
|
||||||
@@ -6067,7 +6076,14 @@ def get_files_folders(starting_folder):
|
|||||||
if os.path.isdir(os.path.join(base_path, item)):
|
if os.path.isdir(os.path.join(base_path, item)):
|
||||||
folders.append([True, item_full_path, item, valid_selection])
|
folders.append([True, item_full_path, item, valid_selection])
|
||||||
else:
|
else:
|
||||||
|
if hide_extention:
|
||||||
|
item = ".".join(item.split(".")[:-1])
|
||||||
|
if valid_only:
|
||||||
|
if valid_selection:
|
||||||
files.append([False, item_full_path, item, valid_selection])
|
files.append([False, item_full_path, item, valid_selection])
|
||||||
|
else:
|
||||||
|
files.append([False, item_full_path, item, valid_selection])
|
||||||
|
|
||||||
items = folders
|
items = folders
|
||||||
if not folder_only:
|
if not folder_only:
|
||||||
items += files
|
items += files
|
||||||
@@ -6226,6 +6242,35 @@ def UI_2_load_model(data):
|
|||||||
print("loading Model")
|
print("loading Model")
|
||||||
load_model(use_gpu=data['use_gpu'], gpu_layers=data['gpu_layers'], disk_layers=data['disk_layers'], online_model=data['online_model'])
|
load_model(use_gpu=data['use_gpu'], gpu_layers=data['gpu_layers'], disk_layers=data['disk_layers'], online_model=data['online_model'])
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when load story is clicked
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('load_story_list')
|
||||||
|
def UI_2_load_story_list(data):
|
||||||
|
file_popup("Select Story to Load", "./stories", "load_story", upload=True, jailed=True, folder_only=False, renameable=True,
|
||||||
|
deleteable=True, show_breadcrumbs=True, item_check=valid_story,
|
||||||
|
valid_only=True, hide_extention=True)
|
||||||
|
|
||||||
|
def valid_story(file):
|
||||||
|
if file.endswith(".json"):
|
||||||
|
with open(file, "r") as f:
|
||||||
|
try:
|
||||||
|
js = json.load(f)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
return 'actions' in js
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered on load story
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('load_story')
|
||||||
|
def UI_2_load_story(file):
|
||||||
|
print("loading {}".format(file))
|
||||||
|
loadRequest(file)
|
||||||
|
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Event triggered to rely a message
|
# Event triggered to rely a message
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
@@ -6234,7 +6279,6 @@ def UI_2_relay(data):
|
|||||||
socketio.emit(data[0], data[1], **data[2])
|
socketio.emit(data[0], data[1], **data[2])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Test
|
# Test
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
|
@@ -685,6 +685,10 @@ td.sequence:hover {
|
|||||||
background-color: #688f1f;
|
background-color: #688f1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.popup .item .file.selected {
|
||||||
|
background: #688f1f;
|
||||||
|
}
|
||||||
|
|
||||||
.popup .popup_load_cancel {
|
.popup .popup_load_cancel {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background-color: var(--popup_title_bar_color);
|
background-color: var(--popup_title_bar_color);
|
||||||
|
@@ -15,6 +15,7 @@ socket.on('popup_edit_file', function(data){popup_edit_file(data);});
|
|||||||
socket.on('show_model_menu', function(data){show_model_menu(data);});
|
socket.on('show_model_menu', function(data){show_model_menu(data);});
|
||||||
socket.on('selected_model_info', function(data){selected_model_info(data);});
|
socket.on('selected_model_info', function(data){selected_model_info(data);});
|
||||||
socket.on('oai_engines', function(data){oai_engines(data);});
|
socket.on('oai_engines', function(data){oai_engines(data);});
|
||||||
|
socket.on('buildload', function(data){buildload(data);});
|
||||||
socket.on('error_popup', function(data){error_popup(data);});
|
socket.on('error_popup', function(data){error_popup(data);});
|
||||||
//socket.onAny(function(event_name, data) {console.log({"event": event_name, "class": data.classname, "data": data});});
|
//socket.onAny(function(event_name, data) {console.log({"event": event_name, "class": data.classname, "data": data});});
|
||||||
|
|
||||||
@@ -365,7 +366,7 @@ function load_popup(data) {
|
|||||||
accept.setAttribute("emit", data.call_back);
|
accept.setAttribute("emit", data.call_back);
|
||||||
accept.setAttribute("selected_value", "");
|
accept.setAttribute("selected_value", "");
|
||||||
accept.onclick = function () {
|
accept.onclick = function () {
|
||||||
socket.emit(this.emit, this.getAttribute("selected_value"));
|
socket.emit(this.getAttribute("emit"), this.getAttribute("selected_value"));
|
||||||
document.getElementById("popup").classList.add("hidden");
|
document.getElementById("popup").classList.add("hidden");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -469,6 +470,11 @@ function popup_items(data) {
|
|||||||
socket.emit("popup_change_folder", this.id);
|
socket.emit("popup_change_folder", this.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var popup_list = document.getElementById('popup_list').getElementsByClassName("selected");
|
||||||
|
for (item of popup_list) {
|
||||||
|
item.classList.remove("selected");
|
||||||
|
}
|
||||||
|
this.classList.add("selected");
|
||||||
};
|
};
|
||||||
list_item.append(popup_item);
|
list_item.append(popup_item);
|
||||||
|
|
||||||
@@ -876,6 +882,9 @@ function load_model() {
|
|||||||
document.getElementById("loadmodelcontainer").classList.add("hidden");
|
document.getElementById("loadmodelcontainer").classList.add("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildload(data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------UI to Server Functions----------------------------------
|
//--------------------------------------------UI to Server Functions----------------------------------
|
||||||
|
|
||||||
|
@@ -62,58 +62,7 @@
|
|||||||
{% include 'story flyout.html' %}
|
{% include 'story flyout.html' %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!------------- Pop-Up ------------------------------->
|
<!------------- Pop-Ups ------------------------------->
|
||||||
<div class="popup hidden" id="popup">
|
{% include 'popups.html' %}
|
||||||
<div class="title" id="popup_title">
|
|
||||||
Popup Title
|
|
||||||
</div>
|
|
||||||
<div id="popup_breadcrumbs"></div>
|
|
||||||
<div class="popup_list_area" id="popup_list"></div>
|
|
||||||
<div class="popup_load_cancel hidden" id="popup_upload">
|
|
||||||
<input type=file id="popup_upload_file">
|
|
||||||
</div>
|
|
||||||
<div>Drag file(s) above or click here to Upload File<input id="popup_upload_input" type=file onchange="upload_file(this)"></div>
|
|
||||||
<div class="popup_load_cancel" id="popup_load_cancel">
|
|
||||||
<button class="btn popup_load_cancel_button" id="popup_accept">Load</button>
|
|
||||||
<button class="btn popup_load_cancel_button" id="popup_cancel" onclick='document.getElementById("popup").classList.add("hidden");'>Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!---------------- Model Load Screen ---------------------->
|
|
||||||
<div class="popup hidden" id="loadmodelcontainer">
|
|
||||||
<div class="title">
|
|
||||||
Select A Model To Load
|
|
||||||
</div>
|
|
||||||
<div id="loadmodellistbreadcrumbs">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div id="loadmodellistcontent" class="popup_list_area"></div>
|
|
||||||
<div class="popup_load_cancel">
|
|
||||||
<div>
|
|
||||||
<input class="hidden" type="text" placeholder="key" id="modelkey" onblur="socket.emit('OAI_Key_Update', {'model': document.getElementById('btn_loadmodelaccept').getAttribute('selected_model'), 'key': this.value});">
|
|
||||||
<input class="hidden" type="text" placeholder="Enter the URL of the server (For example a trycloudflare link)" id="modelurl" onchange="check_enable_model_load()">
|
|
||||||
<input class="hidden" type="text" placeholder="Model Path or Hugging Face Name" id="custommodelname" menu="" onblur="socket.send({'cmd': 'selectmodel', 'data': $(this).attr('menu'), 'path_modelname': $('#custommodelname')[0].value});">
|
|
||||||
<select class="hidden" id="oaimodel"><option value="">Select OAI Model</option></select>
|
|
||||||
</div>
|
|
||||||
<div class="hidden" id=modellayers>
|
|
||||||
<div class="justifyleft">
|
|
||||||
GPU/Disk Layers
|
|
||||||
<span class="helpicon">?
|
|
||||||
<span class="helptext">Number of layers to assign to GPUs and to disk cache. Remaining layers will be put into CPU RAM.</span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="justifyright"><span id="gpu_layers_current">0</span>/<span id="gpu_layers_max">0</span></div>
|
|
||||||
<div id=model_layer_bars style="color: white"></div>
|
|
||||||
<input type=hidden id='gpu_count' value=0/>
|
|
||||||
</div>
|
|
||||||
<div class="box flex-push-right hidden" id=use_gpu_div>
|
|
||||||
<input type="checkbox" data-toggle="toggle" data-onstyle="success" id="use_gpu" checked>
|
|
||||||
<div class="box-label">Use GPU</div>
|
|
||||||
</div>
|
|
||||||
<button type="button" class="btn popup_load_cancel_button disabled" onclick="load_model()" id="btn_loadmodelaccept">Load</button>
|
|
||||||
<button type="button" class="btn popup_load_cancel_button" onclick='document.getElementById("loadmodelcontainer").classList.add("hidden");' id="btn_loadmodelclose">Cancel</button>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
69
templates/popups.html
Normal file
69
templates/popups.html
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<!------------------File Browser--------------->
|
||||||
|
<div class="popup hidden" id="popup">
|
||||||
|
<div class="title" id="popup_title">
|
||||||
|
Popup Title
|
||||||
|
</div>
|
||||||
|
<div id="popup_breadcrumbs"></div>
|
||||||
|
<div class="popup_list_area" id="popup_list"></div>
|
||||||
|
<div class="popup_load_cancel hidden" id="popup_upload">
|
||||||
|
<input type=file id="popup_upload_file">
|
||||||
|
</div>
|
||||||
|
<div>Drag file(s) above or click here to Upload File<input id="popup_upload_input" type=file onchange="upload_file(this)"></div>
|
||||||
|
<div class="popup_load_cancel" id="popup_load_cancel">
|
||||||
|
<button class="btn popup_load_cancel_button" id="popup_accept">Load</button>
|
||||||
|
<button class="btn popup_load_cancel_button" id="popup_cancel" onclick='document.getElementById("popup").classList.add("hidden");'>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!---------------- Model Load Screen ---------------------->
|
||||||
|
<div class="popup hidden" id="loadmodelcontainer">
|
||||||
|
<div class="title">
|
||||||
|
Select A Model To Load
|
||||||
|
</div>
|
||||||
|
<div id="loadmodellistbreadcrumbs">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="loadmodellistcontent" class="popup_list_area"></div>
|
||||||
|
<div class="popup_load_cancel">
|
||||||
|
<div>
|
||||||
|
<input class="hidden" type="text" placeholder="key" id="modelkey" onblur="socket.emit('OAI_Key_Update', {'model': document.getElementById('btn_loadmodelaccept').getAttribute('selected_model'), 'key': this.value});">
|
||||||
|
<input class="hidden" type="text" placeholder="Enter the URL of the server (For example a trycloudflare link)" id="modelurl" onchange="check_enable_model_load()">
|
||||||
|
<input class="hidden" type="text" placeholder="Model Path or Hugging Face Name" id="custommodelname" menu="" onblur="socket.send({'cmd': 'selectmodel', 'data': $(this).attr('menu'), 'path_modelname': $('#custommodelname')[0].value});">
|
||||||
|
<select class="hidden" id="oaimodel"><option value="">Select OAI Model</option></select>
|
||||||
|
</div>
|
||||||
|
<div class="hidden" id=modellayers>
|
||||||
|
<div class="justifyleft">
|
||||||
|
GPU/Disk Layers
|
||||||
|
<span class="helpicon">?
|
||||||
|
<span class="helptext">Number of layers to assign to GPUs and to disk cache. Remaining layers will be put into CPU RAM.</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="justifyright"><span id="gpu_layers_current">0</span>/<span id="gpu_layers_max">0</span></div>
|
||||||
|
<div id=model_layer_bars style="color: white"></div>
|
||||||
|
<input type=hidden id='gpu_count' value=0/>
|
||||||
|
</div>
|
||||||
|
<div class="box flex-push-right hidden" id=use_gpu_div>
|
||||||
|
<input type="checkbox" data-toggle="toggle" data-onstyle="success" id="use_gpu" checked>
|
||||||
|
<div class="box-label">Use GPU</div>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn popup_load_cancel_button disabled" onclick="load_model()" id="btn_loadmodelaccept">Load</button>
|
||||||
|
<button type="button" class="btn popup_load_cancel_button" onclick='document.getElementById("loadmodelcontainer").classList.add("hidden");' id="btn_loadmodelclose">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!---------------- Story Load Screen ---------------------->
|
||||||
|
<div class="popup hidden" id="loadcontainer">
|
||||||
|
<div class="title">
|
||||||
|
<div class="popuptitletext">Select A Story To Load</div>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex;">
|
||||||
|
<div>Save Name</div>
|
||||||
|
<div style="margin-left: auto;"># Actions</div>
|
||||||
|
</div>
|
||||||
|
<div id="popup_list_area">
|
||||||
|
</div>
|
||||||
|
<div class="popup_load_cancel">
|
||||||
|
<button type="button" class="btn btn-primary" id="btn_loadaccept">Load</button>
|
||||||
|
<button type="button" class="btn btn-primary" id="btn_loadclose">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
@@ -50,8 +50,12 @@
|
|||||||
<div id="setting_menu_story" class="hidden settings_category_area">
|
<div id="setting_menu_story" class="hidden settings_category_area">
|
||||||
<div id="Story_Info">
|
<div id="Story_Info">
|
||||||
<div>Story Name: <span class="var_sync_story_story_name"></span></div>
|
<div>Story Name: <span class="var_sync_story_story_name"></span></div>
|
||||||
<div>Token Length: <span id="token_length">0</span></div>
|
<div>
|
||||||
<div><button id="save_story" class="btn action_button var_sync_alt_story_gamesaved" onclick='socket.emit("save_story", "Story123");'>Save Story</button></div>
|
<button id="load_story" class="btn action_button" onclick="socket.emit('load_story_list', '');">Load Story</button>
|
||||||
|
<button id="save_story" class="btn action_button var_sync_alt_story_gamesaved" onclick='socket.emit("save_story", "");'>Save Story</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="setting_tile_area">
|
<div class="setting_tile_area">
|
||||||
{% with menu='Story' %}
|
{% with menu='Story' %}
|
||||||
|
Reference in New Issue
Block a user