Added --remote Mode
First step towards native Colab support, built in Cloudflare tunnels easily allows players to play KoboldAI on another device. This mode also removes buttons that would get you stuck if you have no local PC access.
This commit is contained in:
parent
9760c159fd
commit
136dd71171
23
aiserver.py
23
aiserver.py
|
@ -12,6 +12,7 @@ from tkinter import messagebox
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
import html
|
import html
|
||||||
|
import argparse
|
||||||
|
|
||||||
# KoboldAI
|
# KoboldAI
|
||||||
import fileops
|
import fileops
|
||||||
|
@ -103,6 +104,7 @@ class vars:
|
||||||
acregex_ui = re.compile(r'^ *(>.*)$', re.MULTILINE) # Pattern for matching actions in the HTML-escaped story so we can apply colouring, etc (make sure to encase part to format in parentheses)
|
acregex_ui = re.compile(r'^ *(>.*)$', re.MULTILINE) # Pattern for matching actions in the HTML-escaped story so we can apply colouring, etc (make sure to encase part to format in parentheses)
|
||||||
actionmode = 1
|
actionmode = 1
|
||||||
adventure = False
|
adventure = False
|
||||||
|
remote = False
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Function to get model selection at startup
|
# Function to get model selection at startup
|
||||||
|
@ -152,6 +154,14 @@ def gettokenids(char):
|
||||||
# Startup
|
# Startup
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
|
|
||||||
|
# Parsing Parameters
|
||||||
|
parser = argparse.ArgumentParser(description="My Script")
|
||||||
|
parser.add_argument("--remote", action='store_true')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.remote:
|
||||||
|
vars.remote = True;
|
||||||
|
|
||||||
# Select a model to run
|
# Select a model to run
|
||||||
print("{0}Welcome to the KoboldAI Client!\nSelect an AI model to continue:{1}\n".format(colors.CYAN, colors.END))
|
print("{0}Welcome to the KoboldAI Client!\nSelect an AI model to continue:{1}\n".format(colors.CYAN, colors.END))
|
||||||
getModelSelection()
|
getModelSelection()
|
||||||
|
@ -373,6 +383,9 @@ def index():
|
||||||
def do_connect():
|
def do_connect():
|
||||||
print("{0}Client connected!{1}".format(colors.GREEN, colors.END))
|
print("{0}Client connected!{1}".format(colors.GREEN, colors.END))
|
||||||
emit('from_server', {'cmd': 'connected'})
|
emit('from_server', {'cmd': 'connected'})
|
||||||
|
if(vars.remote):
|
||||||
|
emit('from_server', {'cmd': 'runs_remotely'})
|
||||||
|
|
||||||
if(not vars.gamestarted):
|
if(not vars.gamestarted):
|
||||||
setStartState()
|
setStartState()
|
||||||
sendsettings()
|
sendsettings()
|
||||||
|
@ -1900,10 +1913,18 @@ def randomGameRequest(topic):
|
||||||
# Final startup commands to launch Flask app
|
# Final startup commands to launch Flask app
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
# Load settings from client.settings
|
# Load settings from client.settings
|
||||||
loadsettings()
|
loadsettings()
|
||||||
|
|
||||||
# Start Flask/SocketIO (Blocking, so this must be last method!)
|
# Start Flask/SocketIO (Blocking, so this must be last method!)
|
||||||
print("{0}Server started!\rYou may now connect with a browser at http://127.0.0.1:5000/{1}".format(colors.GREEN, colors.END))
|
print("{0}Server started!\rYou may now connect with a browser at http://127.0.0.1:5000/{1}".format(colors.GREEN, colors.END))
|
||||||
#socketio.run(app, host='0.0.0.0', port=5000)
|
#socketio.run(app, host='0.0.0.0', port=5000)
|
||||||
socketio.run(app)
|
if(vars.remote):
|
||||||
|
from flask_cloudflared import start_cloudflared
|
||||||
|
start_cloudflared(5000)
|
||||||
|
socketio.run(app, host='0.0.0.0', port=5000)
|
||||||
|
else:
|
||||||
|
import webbrowser
|
||||||
|
webbrowser.open_new('http://localhost:5000')
|
||||||
|
socketio.run(app)
|
|
@ -13,3 +13,4 @@ dependencies:
|
||||||
- git
|
- git
|
||||||
- pip:
|
- pip:
|
||||||
- git+https://github.com/finetuneanon/transformers@gpt-neo-localattention3-rp-b
|
- git+https://github.com/finetuneanon/transformers@gpt-neo-localattention3-rp-b
|
||||||
|
- flask-cloudflared
|
|
@ -10,3 +10,6 @@ dependencies:
|
||||||
- pytorch
|
- pytorch
|
||||||
- tensorflow-gpu
|
- tensorflow-gpu
|
||||||
- transformers
|
- transformers
|
||||||
|
- pip
|
||||||
|
- pip:
|
||||||
|
- flask-cloudflared
|
4
play.bat
4
play.bat
|
@ -7,12 +7,12 @@ IF %M%==2 GOTO subfolder
|
||||||
|
|
||||||
:subfolder
|
:subfolder
|
||||||
call miniconda3\condabin\activate
|
call miniconda3\condabin\activate
|
||||||
python aiserver.py
|
python aiserver.py %*
|
||||||
cmd /k
|
cmd /k
|
||||||
|
|
||||||
:drivemap
|
:drivemap
|
||||||
subst K: miniconda3 >nul
|
subst K: miniconda3 >nul
|
||||||
call K:\python\condabin\activate
|
call K:\python\condabin\activate
|
||||||
python aiserver.py
|
python aiserver.py %*
|
||||||
subst K: /D
|
subst K: /D
|
||||||
cmd /k
|
cmd /k
|
|
@ -4,3 +4,4 @@ Flask == 1.1.2
|
||||||
Flask-SocketIO == 5.0.1
|
Flask-SocketIO == 5.0.1
|
||||||
requests == 2.25.1
|
requests == 2.25.1
|
||||||
torch == 1.8.1
|
torch == 1.8.1
|
||||||
|
flask-cloudflared
|
|
@ -926,6 +926,8 @@ $(document).ready(function(){
|
||||||
$("#setadventure").prop('checked', msg.data).change();
|
$("#setadventure").prop('checked', msg.data).change();
|
||||||
// Update adventure state
|
// Update adventure state
|
||||||
setadventure(msg.data);
|
setadventure(msg.data);
|
||||||
|
} else if(msg.cmd == "runs_remotely") {
|
||||||
|
hide([button_loadfrfile, button_savetofile, button_import, button_importwi]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue