mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-30 09:08:51 +00:00
upgraded
This commit is contained in:
parent
dabd0758fd
commit
16ad5945f3
3
.gitignore
vendored
3
.gitignore
vendored
@ -200,3 +200,6 @@ src/taming-transformers
|
|||||||
|
|
||||||
# Remove nogpu
|
# Remove nogpu
|
||||||
.no_gpu
|
.no_gpu
|
||||||
|
|
||||||
|
# Temporary arguments to restart file
|
||||||
|
temp_args.txt
|
93
app.py
93
app.py
@ -14,7 +14,10 @@ __github__ = "https://github.com/ParisNeo/lollms-webui"
|
|||||||
__copyright__ = "Copyright 2023, "
|
__copyright__ = "Copyright 2023, "
|
||||||
__license__ = "Apache 2.0"
|
__license__ = "Apache 2.0"
|
||||||
|
|
||||||
|
main_repo = "https://github.com/ParisNeo/lollms-webui.git"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import git
|
||||||
import logging
|
import logging
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
@ -92,8 +95,71 @@ def get_ip_address():
|
|||||||
# Close the socket
|
# Close the socket
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
|
||||||
|
def check_update(branch_name="main"):
|
||||||
|
try:
|
||||||
|
# Open the repository
|
||||||
|
repo = git.Repo(".")
|
||||||
|
|
||||||
|
# Fetch updates from the remote for the specified branch
|
||||||
|
repo.remotes.origin.fetch(refspec=f"refs/heads/{branch_name}:refs/remotes/origin/{branch_name}")
|
||||||
|
|
||||||
|
# Compare the local and remote commit IDs for the specified branch
|
||||||
|
local_commit = repo.head.commit
|
||||||
|
remote_commit = repo.remotes.origin.refs[branch_name].commit
|
||||||
|
|
||||||
|
# Return True if there are updates, False otherwise
|
||||||
|
return local_commit != remote_commit
|
||||||
|
except Exception as e:
|
||||||
|
# Handle any errors that may occur during the fetch process
|
||||||
|
trace_exception(e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def run_restart_script(args):
|
||||||
|
restart_script = "restart_script.py"
|
||||||
|
|
||||||
|
# Save the arguments to a temporary file
|
||||||
|
temp_file = "temp_args.txt"
|
||||||
|
with open(temp_file, "w") as file:
|
||||||
|
file.write(" ".join(args))
|
||||||
|
|
||||||
|
os.system(f"python {restart_script} {temp_file}")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
def run_update_script(args):
|
||||||
|
update_script = "update_script.py"
|
||||||
|
|
||||||
|
# Convert Namespace object to a dictionary
|
||||||
|
args_dict = vars(args)
|
||||||
|
|
||||||
|
# Filter out any key-value pairs where the value is None
|
||||||
|
valid_args = {key: value for key, value in args_dict.items() if value is not None}
|
||||||
|
|
||||||
|
# Save the arguments to a temporary file
|
||||||
|
temp_file = "temp_args.txt"
|
||||||
|
with open(temp_file, "w") as file:
|
||||||
|
# Convert the valid_args dictionary to a string in the format "key1 value1 key2 value2 ..."
|
||||||
|
arg_string = " ".join([f"--{key} {value}" for key, value in valid_args.items()])
|
||||||
|
file.write(arg_string)
|
||||||
|
|
||||||
|
os.system(f"python {update_script} {temp_file}")
|
||||||
|
|
||||||
|
# Reload the main script with the original arguments
|
||||||
|
if os.path.exists(temp_file):
|
||||||
|
with open(temp_file, "r") as file:
|
||||||
|
args = file.read().split()
|
||||||
|
main_script = "app.py" # Replace with the actual name of your main script
|
||||||
|
os.system(f"python {main_script} {' '.join(args)}")
|
||||||
|
os.remove(temp_file)
|
||||||
|
else:
|
||||||
|
print("Error: Temporary arguments file not found.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
class LoLLMsWebUI(LoLLMsAPPI):
|
class LoLLMsWebUI(LoLLMsAPPI):
|
||||||
def __init__(self, _app, _socketio, config:LOLLMSConfig, config_file_path:Path|str, lollms_paths:LollmsPaths) -> None:
|
def __init__(self, args, _app, _socketio, config:LOLLMSConfig, config_file_path:Path|str, lollms_paths:LollmsPaths) -> None:
|
||||||
|
self.args = args
|
||||||
if len(config.personalities)==0:
|
if len(config.personalities)==0:
|
||||||
config.personalities.append("english/generic/lollms")
|
config.personalities.append("english/generic/lollms")
|
||||||
config["active_personality_id"] = 0
|
config["active_personality_id"] = 0
|
||||||
@ -128,6 +194,8 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
|
|
||||||
self.add_endpoint("/restart_program", "restart_program", self.restart_program, methods=["GET"])
|
self.add_endpoint("/restart_program", "restart_program", self.restart_program, methods=["GET"])
|
||||||
|
|
||||||
|
self.add_endpoint("/check_update", "check_update", self.check_update, methods=["GET"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1046,6 +1114,9 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
# Show file selection dialog
|
# Show file selection dialog
|
||||||
file_path = filedialog.askopenfilename()
|
file_path = filedialog.askopenfilename()
|
||||||
|
|
||||||
|
def check_update(self):
|
||||||
|
res = check_update()
|
||||||
|
return jsonify({'update_availability':res})
|
||||||
|
|
||||||
def restart_program(self):
|
def restart_program(self):
|
||||||
ASCIIColors.info("")
|
ASCIIColors.info("")
|
||||||
@ -1057,8 +1128,22 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
ASCIIColors.info("")
|
ASCIIColors.info("")
|
||||||
ASCIIColors.info("")
|
ASCIIColors.info("")
|
||||||
ASCIIColors.info("")
|
ASCIIColors.info("")
|
||||||
python = sys.executable
|
run_restart_script(self.args)
|
||||||
os.execl(python, python, *sys.argv)
|
|
||||||
|
|
||||||
|
|
||||||
|
def update_software(self):
|
||||||
|
ASCIIColors.info("")
|
||||||
|
ASCIIColors.info("")
|
||||||
|
ASCIIColors.info("")
|
||||||
|
ASCIIColors.info(" ╔══════════════════════════════════════════════════╗")
|
||||||
|
ASCIIColors.info(" ║ Updating backend ║")
|
||||||
|
ASCIIColors.info(" ╚══════════════════════════════════════════════════╝")
|
||||||
|
ASCIIColors.info("")
|
||||||
|
ASCIIColors.info("")
|
||||||
|
ASCIIColors.info("")
|
||||||
|
run_update_script(self.args)
|
||||||
|
|
||||||
|
|
||||||
def reload_binding(self):
|
def reload_binding(self):
|
||||||
try:
|
try:
|
||||||
@ -1681,7 +1766,7 @@ if __name__ == "__main__":
|
|||||||
# Remove the .no_gpu file
|
# Remove the .no_gpu file
|
||||||
no_gpu_file.unlink()
|
no_gpu_file.unlink()
|
||||||
|
|
||||||
bot = LoLLMsWebUI(app, socketio, config, config.file_path, lollms_paths)
|
bot = LoLLMsWebUI(args, app, socketio, config, config.file_path, lollms_paths)
|
||||||
|
|
||||||
# chong Define custom WebSocketHandler with error handling
|
# chong Define custom WebSocketHandler with error handling
|
||||||
class CustomWebSocketHandler(WebSocketHandler):
|
class CustomWebSocketHandler(WebSocketHandler):
|
||||||
|
@ -12,3 +12,4 @@ langchain
|
|||||||
requests
|
requests
|
||||||
eventlet
|
eventlet
|
||||||
websocket-client
|
websocket-client
|
||||||
|
git
|
@ -10,3 +10,4 @@ gpt4all-j
|
|||||||
gpt4all
|
gpt4all
|
||||||
transformers
|
transformers
|
||||||
pyaipersonality>=0.0.11
|
pyaipersonality>=0.0.11
|
||||||
|
git
|
22
restart_script.py
Normal file
22
restart_script.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage: python restart_script.py <repo_path>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Reload the main script with the original arguments
|
||||||
|
temp_file = "temp_args.txt"
|
||||||
|
if os.path.exists(temp_file):
|
||||||
|
with open(temp_file, "r") as file:
|
||||||
|
args = file.read().split()
|
||||||
|
main_script = "app.py"
|
||||||
|
os.system(f"python {main_script} {' '.join(args)}")
|
||||||
|
os.remove(temp_file)
|
||||||
|
else:
|
||||||
|
print("Error: Temporary arguments file not found.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
48
update_script.py
Normal file
48
update_script.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import git
|
||||||
|
import subprocess
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
def run_git_pull(repo_path):
|
||||||
|
try:
|
||||||
|
repo = git.Repo(repo_path)
|
||||||
|
origin = repo.remotes.origin
|
||||||
|
origin.pull()
|
||||||
|
except git.GitCommandError as e:
|
||||||
|
print(f"Error during git pull: {e}")
|
||||||
|
|
||||||
|
def install_requirements():
|
||||||
|
try:
|
||||||
|
subprocess.check_call(["pip", "install", "-r", "requirements.txt"])
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error during pip install: {e}")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--repo", type=str, default="https://github.com/ParisNeo/lollms-webui.git", help="Path to the Git repository")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
repo_path = args.repo
|
||||||
|
|
||||||
|
# Perform git pull to update the repository
|
||||||
|
run_git_pull(repo_path)
|
||||||
|
|
||||||
|
# Install the new requirements
|
||||||
|
install_requirements()
|
||||||
|
|
||||||
|
# Reload the main script with the original arguments
|
||||||
|
temp_file = "temp_args.txt"
|
||||||
|
if os.path.exists(temp_file):
|
||||||
|
with open(temp_file, "r") as file:
|
||||||
|
args = file.read().split()
|
||||||
|
main_script = "app.py" # Replace with the actual name of your main script
|
||||||
|
os.system(f"python {main_script} {' '.join(args)}")
|
||||||
|
os.remove(temp_file)
|
||||||
|
else:
|
||||||
|
print("Error: Temporary arguments file not found.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
web/dist/index.html
vendored
4
web/dist/index.html
vendored
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>LoLLMS WebUI - Welcome</title>
|
<title>LoLLMS WebUI - Welcome</title>
|
||||||
<script type="module" crossorigin src="/assets/index-18032900.js"></script>
|
<script type="module" crossorigin src="/assets/index-657d4196.js"></script>
|
||||||
<link rel="stylesheet" href="/assets/index-cf16d40a.css">
|
<link rel="stylesheet" href="/assets/index-2cdce675.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
@ -846,7 +846,7 @@ export default {
|
|||||||
|
|
||||||
let responseMessage = {
|
let responseMessage = {
|
||||||
//content:msgObj.data,
|
//content:msgObj.data,
|
||||||
content: msgObj.message,// "✍ please stand by ...",//msgObj.message,
|
content: "✍ please stand by ...",
|
||||||
created_at:msgObj.created_at,
|
created_at:msgObj.created_at,
|
||||||
binding:msgObj.binding,
|
binding:msgObj.binding,
|
||||||
model:msgObj.model,
|
model:msgObj.model,
|
||||||
|
@ -688,12 +688,13 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<!-- Row 0 -->
|
<!-- Row 0 -->
|
||||||
<div class="w-full">
|
<div v-if="has_updates" class="w-full">
|
||||||
<button
|
<button
|
||||||
class="hover:text-secondary w-full bg-red-100 m-2 p-2 duration-75 flex justify-center w-full hover:bg-bg-light-tone hover:dark:bg-bg-dark-tone rounded-lg"
|
class="hover:text-secondary w-full bg-red-100 m-2 p-2 duration-75 flex justify-center w-full hover:bg-bg-light-tone hover:dark:bg-bg-dark-tone rounded-lg"
|
||||||
@click="api_get_req('update_software').then((res)=>{if(res.status){this.$refs.toast.showToast('Success!', 4, true)}else{this.$refs.toast.showToast('Success!', 4, true)}})"
|
@click="api_get_req('update_software').then((res)=>{if(res.status){this.$refs.toast.showToast('Success!', 4, true)}else{this.$refs.toast.showToast('Success!', 4, true)}})"
|
||||||
>
|
>
|
||||||
Upgrade program
|
Upgrade program
|
||||||
|
<i data-feather="alert-circle"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -2871,6 +2872,12 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
has_updates:{
|
||||||
|
async get(){
|
||||||
|
res = await this.api_get_req("check_update")
|
||||||
|
return res["update_availability"]
|
||||||
|
}
|
||||||
|
},
|
||||||
configFile: {
|
configFile: {
|
||||||
get() {
|
get() {
|
||||||
return this.$store.state.config;
|
return this.$store.state.config;
|
||||||
|
Loading…
Reference in New Issue
Block a user