mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
More save stuff
This commit is contained in:
@@ -9694,7 +9694,7 @@ def UI_2_test_match():
|
|||||||
@logger.catch
|
@logger.catch
|
||||||
def UI_2_audio():
|
def UI_2_audio():
|
||||||
action_id = int(request.args['id']) if 'id' in request.args else len(koboldai_vars.actions)
|
action_id = int(request.args['id']) if 'id' in request.args else len(koboldai_vars.actions)
|
||||||
filename="stories/{}/{}.ogg".format(koboldai_vars.story_id, action_id)
|
filename = os.path.join(koboldai_vars.save_paths.generated_audio, f"{action_id}.ogg")
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
koboldai_vars.actions.gen_audio(action_id)
|
koboldai_vars.actions.gen_audio(action_id)
|
||||||
return send_file(
|
return send_file(
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import os, re, time, threading, json, pickle, base64, copy, tqdm, datetime, sys
|
import os, re, time, threading, json, pickle, base64, copy, tqdm, datetime, sys
|
||||||
|
import shutil
|
||||||
from typing import Union
|
from typing import Union
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from flask import has_request_context, session
|
from flask import has_request_context, session
|
||||||
@@ -907,6 +908,15 @@ class story_settings(settings):
|
|||||||
os.mkdir(self.save_paths.generated_audio)
|
os.mkdir(self.save_paths.generated_audio)
|
||||||
os.mkdir(self.save_paths.generated_images)
|
os.mkdir(self.save_paths.generated_images)
|
||||||
|
|
||||||
|
# Convert v2 if applicable
|
||||||
|
v2_path = os.path.join("stories", f"{self.story_name}_v2.json")
|
||||||
|
if os.path.exists(v2_path):
|
||||||
|
logger.info("Migrating v2 save")
|
||||||
|
with open(v2_path, "r") as file:
|
||||||
|
v2j = json.load(file)
|
||||||
|
assert v2j["story_id"] == self.story_id
|
||||||
|
shutil.move(v2_path, os.path.join(self.save_paths.base, ".v2_old.json"))
|
||||||
|
|
||||||
with open(self.save_paths.story, "w") as file:
|
with open(self.save_paths.story, "w") as file:
|
||||||
file.write(self.to_json())
|
file.write(self.to_json())
|
||||||
self.gamesaved = True
|
self.gamesaved = True
|
||||||
@@ -985,6 +995,7 @@ class story_settings(settings):
|
|||||||
if name == "gamesaved" and value == False and self.autosave:
|
if name == "gamesaved" and value == False and self.autosave:
|
||||||
logger.debug("Saving story from gamesaved change and on autosave")
|
logger.debug("Saving story from gamesaved change and on autosave")
|
||||||
self.save_story()
|
self.save_story()
|
||||||
|
|
||||||
if not new_variable and old_value != value:
|
if not new_variable and old_value != value:
|
||||||
#Change game save state
|
#Change game save state
|
||||||
if name in ['story_name', 'prompt', 'memory', 'authornote', 'authornotetemplate', 'andepth', 'chatname', 'actionmode', 'dynamicscan', 'notes', 'biases']:
|
if name in ['story_name', 'prompt', 'memory', 'authornote', 'authornotetemplate', 'andepth', 'chatname', 'actionmode', 'dynamicscan', 'notes', 'biases']:
|
||||||
@@ -1002,6 +1013,9 @@ class story_settings(settings):
|
|||||||
#reset the story id if we change the name
|
#reset the story id if we change the name
|
||||||
self.story_id = int.from_bytes(os.urandom(16), 'little', signed=True)
|
self.story_id = int.from_bytes(os.urandom(16), 'little', signed=True)
|
||||||
|
|
||||||
|
# Story name influences save base
|
||||||
|
self.save_paths.base = os.path.join("stories", self.story_name or "Untitled")
|
||||||
|
|
||||||
#Recalc AI Text
|
#Recalc AI Text
|
||||||
elif name == 'authornote':
|
elif name == 'authornote':
|
||||||
ignore = self.koboldai_vars.calc_ai_text()
|
ignore = self.koboldai_vars.calc_ai_text()
|
||||||
@@ -1040,8 +1054,6 @@ class story_settings(settings):
|
|||||||
elif name == 'chatmode' and value == False and self.adventure == False:
|
elif name == 'chatmode' and value == False and self.adventure == False:
|
||||||
self.storymode = 0
|
self.storymode = 0
|
||||||
self.actionmode = 0
|
self.actionmode = 0
|
||||||
elif name == "story_name":
|
|
||||||
self.save_paths.base = os.path.join("stories", self.story_name or "Untitled")
|
|
||||||
|
|
||||||
class user_settings(settings):
|
class user_settings(settings):
|
||||||
local_only_variables = ['socketio', 'importjs']
|
local_only_variables = ['socketio', 'importjs']
|
||||||
@@ -1814,9 +1826,7 @@ class KoboldStoryRegister(object):
|
|||||||
#self.tts_model.to(torch.device(0)) # gpu or cpu
|
#self.tts_model.to(torch.device(0)) # gpu or cpu
|
||||||
self.tts_model.to(torch.device("cpu")) # gpu or cpu
|
self.tts_model.to(torch.device("cpu")) # gpu or cpu
|
||||||
|
|
||||||
filename="stories/{}/{}.ogg".format(self.story_settings.story_id, action_id)
|
filename = os.path.join(self.koboldai_vars.save_paths.generated_audio, f"{action_id}.ogg")
|
||||||
if not os.path.exists("stories/{}".format(self.story_settings.story_id)):
|
|
||||||
os.mkdir("stories/{}".format(self.story_settings.story_id))
|
|
||||||
|
|
||||||
if overwrite or not os.path.exists(filename):
|
if overwrite or not os.path.exists(filename):
|
||||||
self.make_audio_queue.put((self.actions[action_id]['Selected Text'], filename))
|
self.make_audio_queue.put((self.actions[action_id]['Selected Text'], filename))
|
||||||
|
@@ -2590,14 +2590,14 @@ function process_log_message(full_data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------UI to Server Functions----------------------------------
|
//--------------------------------------------UI to Server Functions----------------------------------
|
||||||
async function download_story_to_json() {
|
async function download_story_to_zip() {
|
||||||
//document.getElementById('download_iframe').src = 'json';
|
//document.getElementById('download_iframe').src = 'json';
|
||||||
downloaded = false;
|
downloaded = false;
|
||||||
if (socket.connected) {
|
if (socket.connected) {
|
||||||
try {
|
try {
|
||||||
let r = await fetch("json");
|
let r = await fetch("zip");
|
||||||
let j = await r.json();
|
let j = await r.json();
|
||||||
downloadString(JSON.stringify(j), j['story_name']+".json")
|
downloadString(JSON.stringify(j), j['story_name']+".kaistory")
|
||||||
downloaded = true;
|
downloaded = true;
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
|
@@ -60,7 +60,7 @@
|
|||||||
<span class="var_sync_story_story_name fullwidth" contenteditable=true onblur="sync_to_server(this);"></span>
|
<span class="var_sync_story_story_name fullwidth" contenteditable=true onblur="sync_to_server(this);"></span>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
<span class="material-icons-outlined cursor" style="padding-top: 8px;" tooltip="Download Story" onclick="download_story_to_json()">file_download</span>
|
<span class="material-icons-outlined cursor" style="padding-top: 8px;" tooltip="Download Story" onclick="download_story_to_zip()">file_download</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="text_storyname">
|
<div id="text_storyname">
|
||||||
|
Reference in New Issue
Block a user