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
|
||||
def UI_2_audio():
|
||||
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):
|
||||
koboldai_vars.actions.gen_audio(action_id)
|
||||
return send_file(
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
import os, re, time, threading, json, pickle, base64, copy, tqdm, datetime, sys
|
||||
import shutil
|
||||
from typing import Union
|
||||
from io import BytesIO
|
||||
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_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:
|
||||
file.write(self.to_json())
|
||||
self.gamesaved = True
|
||||
@@ -985,6 +995,7 @@ class story_settings(settings):
|
||||
if name == "gamesaved" and value == False and self.autosave:
|
||||
logger.debug("Saving story from gamesaved change and on autosave")
|
||||
self.save_story()
|
||||
|
||||
if not new_variable and old_value != value:
|
||||
#Change game save state
|
||||
if name in ['story_name', 'prompt', 'memory', 'authornote', 'authornotetemplate', 'andepth', 'chatname', 'actionmode', 'dynamicscan', 'notes', 'biases']:
|
||||
@@ -1001,6 +1012,9 @@ class story_settings(settings):
|
||||
elif name == 'story_name':
|
||||
#reset the story id if we change the name
|
||||
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
|
||||
elif name == 'authornote':
|
||||
@@ -1040,8 +1054,6 @@ class story_settings(settings):
|
||||
elif name == 'chatmode' and value == False and self.adventure == False:
|
||||
self.storymode = 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):
|
||||
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("cpu")) # gpu or cpu
|
||||
|
||||
filename="stories/{}/{}.ogg".format(self.story_settings.story_id, action_id)
|
||||
if not os.path.exists("stories/{}".format(self.story_settings.story_id)):
|
||||
os.mkdir("stories/{}".format(self.story_settings.story_id))
|
||||
filename = os.path.join(self.koboldai_vars.save_paths.generated_audio, f"{action_id}.ogg")
|
||||
|
||||
if overwrite or not os.path.exists(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----------------------------------
|
||||
async function download_story_to_json() {
|
||||
async function download_story_to_zip() {
|
||||
//document.getElementById('download_iframe').src = 'json';
|
||||
downloaded = false;
|
||||
if (socket.connected) {
|
||||
try {
|
||||
let r = await fetch("json");
|
||||
let r = await fetch("zip");
|
||||
let j = await r.json();
|
||||
downloadString(JSON.stringify(j), j['story_name']+".json")
|
||||
downloadString(JSON.stringify(j), j['story_name']+".kaistory")
|
||||
downloaded = true;
|
||||
}
|
||||
catch(err) {
|
||||
|
@@ -60,7 +60,7 @@
|
||||
<span class="var_sync_story_story_name fullwidth" contenteditable=true onblur="sync_to_server(this);"></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>
|
||||
</div>
|
||||
<div id="text_storyname">
|
||||
|
Reference in New Issue
Block a user