From 136dd711719db22a9ffba9331454f5518b9fcd74 Mon Sep 17 00:00:00 2001 From: henk717 Date: Fri, 20 Aug 2021 00:37:59 +0200 Subject: [PATCH] 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. --- aiserver.py | 23 ++++++++++++++++++++++- environments/finetuneanon.yml | 3 ++- environments/huggingface.yml | 5 ++++- play.bat | 4 ++-- requirements.txt | 3 ++- static/application.js | 2 ++ 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/aiserver.py b/aiserver.py index bb6965b8..4fa62615 100644 --- a/aiserver.py +++ b/aiserver.py @@ -12,6 +12,7 @@ from tkinter import messagebox import json import requests import html +import argparse # KoboldAI 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) actionmode = 1 adventure = False + remote = False #==================================================================# # Function to get model selection at startup @@ -152,6 +154,14 @@ def gettokenids(char): # 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 print("{0}Welcome to the KoboldAI Client!\nSelect an AI model to continue:{1}\n".format(colors.CYAN, colors.END)) getModelSelection() @@ -373,6 +383,9 @@ def index(): def do_connect(): print("{0}Client connected!{1}".format(colors.GREEN, colors.END)) emit('from_server', {'cmd': 'connected'}) + if(vars.remote): + emit('from_server', {'cmd': 'runs_remotely'}) + if(not vars.gamestarted): setStartState() sendsettings() @@ -1900,10 +1913,18 @@ def randomGameRequest(topic): # Final startup commands to launch Flask app #==================================================================# if __name__ == "__main__": + # Load settings from client.settings loadsettings() # 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)) #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) \ No newline at end of file diff --git a/environments/finetuneanon.yml b/environments/finetuneanon.yml index 2ac0cc55..7a23b7a2 100644 --- a/environments/finetuneanon.yml +++ b/environments/finetuneanon.yml @@ -12,4 +12,5 @@ dependencies: - pip - git - pip: - - git+https://github.com/finetuneanon/transformers@gpt-neo-localattention3-rp-b \ No newline at end of file + - git+https://github.com/finetuneanon/transformers@gpt-neo-localattention3-rp-b + - flask-cloudflared \ No newline at end of file diff --git a/environments/huggingface.yml b/environments/huggingface.yml index bfbd33e5..659ecc74 100644 --- a/environments/huggingface.yml +++ b/environments/huggingface.yml @@ -9,4 +9,7 @@ dependencies: - flask-socketio - pytorch - tensorflow-gpu - - transformers \ No newline at end of file + - transformers + - pip + - pip: + - flask-cloudflared \ No newline at end of file diff --git a/play.bat b/play.bat index 2d723fd9..db05b27e 100644 --- a/play.bat +++ b/play.bat @@ -7,12 +7,12 @@ IF %M%==2 GOTO subfolder :subfolder call miniconda3\condabin\activate -python aiserver.py +python aiserver.py %* cmd /k :drivemap subst K: miniconda3 >nul call K:\python\condabin\activate -python aiserver.py +python aiserver.py %* subst K: /D cmd /k \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 043a9d4b..a17ea08f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ tensorflow-gpu Flask == 1.1.2 Flask-SocketIO == 5.0.1 requests == 2.25.1 -torch == 1.8.1 \ No newline at end of file +torch == 1.8.1 +flask-cloudflared \ No newline at end of file diff --git a/static/application.js b/static/application.js index 4de2409d..3963ed8a 100644 --- a/static/application.js +++ b/static/application.js @@ -926,6 +926,8 @@ $(document).ready(function(){ $("#setadventure").prop('checked', msg.data).change(); // Update adventure state setadventure(msg.data); + } else if(msg.cmd == "runs_remotely") { + hide([button_loadfrfile, button_savetofile, button_import, button_importwi]); } });