Replaced easygui with tkinter to address file prompts appearing beneath game window

Removed easygui from requirements.txt
Save directory is no longer stored in save file for privacy
This commit is contained in:
KoboldAI Dev 2021-05-05 11:18:24 -04:00
parent 229b10cb91
commit a27d5beb36
3 changed files with 49 additions and 18 deletions

View File

@ -5,8 +5,9 @@
#==================================================================#
from os import path, getcwd
from tkinter import filedialog, messagebox
import tkinter as tk
import json
import easygui
import torch
#==================================================================#
@ -58,7 +59,7 @@ class vars:
editln = 0 # Which line was last selected in Edit Mode
url = "https://api.inferkit.com/v1/models/standard/generate" # InferKit API URL
apikey = "" # API key to use for InferKit API calls
savedir = getcwd()+"\stories\\newstory.json"
savedir = getcwd()+"\stories"
hascuda = False # Whether torch has detected CUDA on the system
usegpu = False # Whether to launch pipeline with GPU support
custmodpth = "" # Filesystem location of custom model to run
@ -90,8 +91,16 @@ def getModelSelection():
# If custom model was selected, get the filesystem location and store it
if(vars.model == "NeoCustom" or vars.model == "GPT2Custom"):
print("{0}Please choose the folder where pytorch_model.bin is located:{1}\n".format(colors.OKCYAN, colors.ENDC))
path = easygui.diropenbox (default=getcwd())
if(path != None):
root = tk.Tk()
root.attributes("-topmost", True)
path = filedialog.askdirectory(
initialdir=getcwd(),
title="Select Model Folder",
)
root.destroy()
if(path != None and path != ""):
# Save directory to vars
vars.custmodpth = path
else:
@ -143,7 +152,9 @@ if(vars.model == "InferKit"):
vars.apikey = input("Key> ")
# Write API key to file
file = open("client.settings", "w")
try:
file.write("{\"apikey\": \""+vars.apikey+"\"}")
finally:
file.close()
else:
# Otherwise open it up and get the key
@ -686,9 +697,16 @@ def exitModes():
# Save the story to a file
#==================================================================#
def saveRequest():
path = easygui.filesavebox(default=vars.savedir)
root = tk.Tk()
root.attributes("-topmost", True)
path = filedialog.asksaveasfile(
initialdir=vars.savedir,
title="Save Story As",
filetypes = [("Json", "*.json")]
)
root.destroy()
if(path != None):
if(path != None and path != ''):
# Leave Edit/Memory mode before continuing
exitModes()
# Save path for future saves
@ -704,19 +722,28 @@ def saveRequest():
js["memory"] = vars.memory
js["authorsnote"] = vars.authornote
js["actions"] = vars.actions
js["savedir"] = path
#js["savedir"] = path.name # For privacy, don't include savedir in save file
# Write it
file = open(path, "w")
file = open(path.name, "w")
try:
file.write(json.dumps(js))
finally:
file.close()
#==================================================================#
# Load a stored story from a file
#==================================================================#
def loadRequest():
path = easygui.fileopenbox(default=vars.savedir) # Returns None on cancel
root = tk.Tk()
root.attributes("-topmost", True)
path = filedialog.askopenfilename(
initialdir=vars.savedir,
title="Select Story File",
filetypes = [("Json", "*.json")]
)
root.destroy()
if(path != None):
if(path != None and path != ''):
# Leave Edit/Memory mode before continuing
exitModes()
# Read file contents into JSON object
@ -731,7 +758,7 @@ def loadRequest():
vars.prompt = js["prompt"]
vars.memory = js["memory"]
vars.actions = js["actions"]
vars.savedir = js["savedir"]
#vars.savedir = js["savedir"] # For privacy, don't include savedir in save file
# Try not to break older save files
if("authorsnote" in js):
@ -747,7 +774,12 @@ def loadRequest():
#==================================================================#
def newGameRequest():
# Ask for confirmation
if(easygui.ccbox("Really start new Story?","Please Confirm")):
root = tk.Tk()
root.attributes("-topmost", True)
confirm = messagebox.askquestion("Confirm New Game", "Really start new Story?")
root.destroy()
if(confirm == "yes"):
# Leave Edit/Memory mode before continuing
exitModes()
# Clear vars values

View File

@ -3,5 +3,4 @@ tensorflow-gpu
Flask == 1.1.2
Flask-SocketIO == 5.0.1
requests == 2.25.1
easygui == 0.98.2
torch == 1.8.1

View File

@ -1 +1 @@
{"gamestarted": true, "prompt": "Niko the kobold stalked carefully down the alley, his small scaly figure obscured by a dusky cloak that fluttered lightly in the cold winter breeze. Holding up his tail to keep it from dragging in the dirty snow that covered the cobblestone, he waited patiently for the butcher to turn his attention from his stall so that he could pilfer his next meal: a tender-looking", "memory": "Niko is a small red kobold.\nNiko has yellow, reptilian eyes and a long, scaly tail.\nNiko is hungry and looking to steal something to eat.", "authorsnote": "Things are about to get crazy for poor Niko.", "actions": [" chicken. He crouched just slightly as he neared the stall to ensure that no one was watching, not that anyone would be dumb enough to hassle a small kobold. What else was there for a lowly kobold to", " do in a city? All that Niko needed to know was", " where to find the chicken and then how to make off with it.\n\nA soft thud caused Niko to quickly lift his head. Standing behind the stall where the butcher had been cutting his chicken,"], "savedir": ""}
{"gamestarted": true, "prompt": "Niko the kobold stalked carefully down the alley, his small scaly figure obscured by a dusky cloak that fluttered lightly in the cold winter breeze. Holding up his tail to keep it from dragging in the dirty snow that covered the cobblestone, he waited patiently for the butcher to turn his attention from his stall so that he could pilfer his next meal: a tender-looking", "memory": "Niko is a small red kobold.\nNiko has yellow, reptilian eyes and a long, scaly tail.\nNiko is hungry and looking to steal something to eat.", "authorsnote": "Things are about to get crazy for poor Niko.", "actions": [" chicken. He crouched just slightly as he neared the stall to ensure that no one was watching, not that anyone would be dumb enough to hassle a small kobold. What else was there for a lowly kobold to", " do in a city? All that Niko needed to know was", " where to find the chicken and then how to make off with it.\n\nA soft thud caused Niko to quickly lift his head. Standing behind the stall where the butcher had been cutting his chicken,"]}