Initial Load Story dialog

This commit is contained in:
ebolam
2022-07-01 19:24:20 -04:00
parent 1e815e7f52
commit 516564ef6c
6 changed files with 144 additions and 65 deletions

View File

@@ -5201,7 +5201,7 @@ def saveRequest(savpath, savepins=True):
#==================================================================#
# Show list of saved stories
#==================================================================#
def getloadlist():
def getloadlist(data=None):
emit('from_server', {'cmd': 'buildload', 'data': fileops.getstoryfiles()}, room="UI_1")
#==================================================================#
@@ -5869,11 +5869,6 @@ def ui2_connect():
#==================================================================#
# 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')
def upload_file(data):
print("upload_file {}".format(data['filename']))
@@ -5996,7 +5991,9 @@ def popup_change_file(data):
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))
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
#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
@@ -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
#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?
#valid_only = only show valid files
#hide_extention = hide extensions
if jailed:
session['popup_jailed_dir'] = os.path.abspath(starting_folder).replace("\\", "/")
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_show_breadcrumbs'] = show_breadcrumbs
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_1")
@@ -6032,6 +6033,8 @@ def get_files_folders(starting_folder):
show_breadcrumbs = session['popup_show_breadcrumbs']
show_hidden = session['popup_show_hidden']
folder_only = session['popup_folder_only']
valid_only = session['valid_only']
hide_extention = session['hide_extention']
if starting_folder == 'This PC':
breadcrumbs = [['This PC', 'This PC']]
@@ -6049,6 +6052,12 @@ def get_files_folders(starting_folder):
else:
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'])
#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 = []
files = []
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)):
folders.append([True, item_full_path, item, valid_selection])
else:
files.append([False, item_full_path, item, valid_selection])
if hide_extention:
item = ".".join(item.split(".")[:-1])
if valid_only:
if valid_selection:
files.append([False, item_full_path, item, valid_selection])
else:
files.append([False, item_full_path, item, valid_selection])
items = folders
if not folder_only:
items += files
@@ -6226,6 +6242,35 @@ def UI_2_load_model(data):
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'])
#==================================================================#
# 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
#==================================================================#
@@ -6233,7 +6278,6 @@ def UI_2_load_model(data):
def UI_2_relay(data):
socketio.emit(data[0], data[1], **data[2])
#==================================================================#
# Test

View File

@@ -685,6 +685,10 @@ td.sequence:hover {
background-color: #688f1f;
}
.popup .item .file.selected {
background: #688f1f;
}
.popup .popup_load_cancel {
text-align: center;
background-color: var(--popup_title_bar_color);

View File

@@ -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('selected_model_info', function(data){selected_model_info(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.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("selected_value", "");
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");
};
}
@@ -469,6 +470,11 @@ function popup_items(data) {
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);
@@ -876,6 +882,9 @@ function load_model() {
document.getElementById("loadmodelcontainer").classList.add("hidden");
}
function buildload(data) {
console.log(data);
}
//--------------------------------------------UI to Server Functions----------------------------------

View File

@@ -62,58 +62,7 @@
{% include 'story flyout.html' %}
</div>
<!------------- Pop-Up ------------------------------->
<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>
<!------------- Pop-Ups ------------------------------->
{% include 'popups.html' %}
</body>
</html>

69
templates/popups.html Normal file
View 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>

View File

@@ -50,8 +50,12 @@
<div id="setting_menu_story" class="hidden settings_category_area">
<div id="Story_Info">
<div>Story Name: <span class="var_sync_story_story_name"></span></div>
<div>Token Length: <span id="token_length">0</span></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>
<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 class="setting_tile_area">
{% with menu='Story' %}