This commit is contained in:
Saifeddine ALOUI 2024-01-07 22:34:33 +01:00
parent 0766c5f8a0
commit 448d90b25e
7 changed files with 73 additions and 26 deletions

@ -1 +1 @@
Subproject commit 310eafa0abd54e1e9cd5c5c49a3b26a312dd95cb
Subproject commit fb402a5d3d043efbecd7199ea45927d6ad37af6c

View File

@ -20,10 +20,10 @@ from lollms.paths import LollmsPaths
from lollms.helpers import ASCIIColors, trace_exception
from lollms.com import NotificationType, NotificationDisplayType, LoLLMsCom
from lollms.app import LollmsApplication
from lollms.utilities import File64BitsManager, PromptReshaper, PackageManager, find_first_available_file_index
from lollms.utilities import File64BitsManager, PromptReshaper, PackageManager, find_first_available_file_index, run_async
import git
import asyncio
import os
try:
from lollms.media import WebcamImageSender, AudioRecorder
Media_on=True
@ -316,7 +316,24 @@ class LOLLMSWebUI(LOLLMSElfServer):
sys.exit(0)
def run_restart_script(self, args):
restart_script = Path(__file__).parent/"restart_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 = Path(__file__).parent/"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 {restart_script}")
sys.exit(0)
def audio_callback(self, output):
if self.summoned:
@ -942,9 +959,10 @@ class LOLLMSWebUI(LOLLMSElfServer):
duration:int=4,
client_id=None,
display_type:NotificationDisplayType=NotificationDisplayType.TOAST,
verbose=True
verbose=True,
):
asyncio.run(
run_async(
self.socketio.emit('notification', {
'content': content,# self.connections[client_id]["generated_text"],
'notification_type': notification_type.value,
@ -992,7 +1010,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
model = self.config["model_name"],
personality = self.config["personalities"][self.config["active_personality_id"]],
) # first the content is empty, but we'll fill it at the end
asyncio.run(
run_async(
self.socketio.emit('new_message',
{
"sender": sender,
@ -1026,7 +1044,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
self.connections[client_id]["current_discussion"].current_message.finished_generating_at=datetime.now().strftime('%Y-%m-%d %H:%M:%S')
mtdt = json.dumps(metadata, indent=4) if metadata is not None and type(metadata)== list else metadata
if self.nb_received_tokens==1:
asyncio.run(
run_async(
self.socketio.emit('update_message', {
"sender": self.personality.name,
'id':self.connections[client_id]["current_discussion"].current_message.id,
@ -1041,7 +1059,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
)
)
asyncio.run(
run_async(
self.socketio.emit('update_message', {
"sender": self.personality.name,
'id':self.connections[client_id]["current_discussion"].current_message.id,
@ -1067,7 +1085,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
self.connections[client_id]["generated_text"]=self.connections[client_id]["generated_text"].split("!@>")[0]
# Send final message
self.connections[client_id]["current_discussion"].current_message.finished_generating_at=datetime.now().strftime('%Y-%m-%d %H:%M:%S')
asyncio.run(
run_async(
self.socketio.emit('close_message', {
"sender": self.personality.name,
"id": self.connections[client_id]["current_discussion"].current_message.id,
@ -1125,7 +1143,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
if message_type == MSG_TYPE.MSG_TYPE_NEW_MESSAGE:
self.nb_received_tokens = 0
self.start_time = datetime.now()
asyncio.run(
run_async(
self.new_message(
client_id,
self.personality.name if personality is None else personality.name,
@ -1404,7 +1422,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
if ttl is None or ttl=="" or ttl=="untitled":
title = self.make_discussion_title(d, client_id=client_id)
d.rename(title)
asyncio.run(
run_async(
self.socketio.emit('disucssion_renamed',{
'status': True,
'discussion_id':d.discussion_id,
@ -1424,4 +1442,4 @@ class LOLLMSWebUI(LOLLMSElfServer):
print()
self.busy=False
return ""
return ""

View File

@ -12,6 +12,7 @@ from fastapi.responses import HTMLResponse
from lollms.app import LollmsApplication
from lollms.paths import LollmsPaths
from lollms.main_config import LOLLMSConfig
from lollms.utilities import trace_exception
from lollms_webui import LOLLMSWebUI
from pathlib import Path
from ascii_colors import ASCIIColors
@ -19,6 +20,7 @@ import socketio
import uvicorn
import argparse
from socketio import ASGIApp
import webbrowser
app = FastAPI()
@ -57,7 +59,7 @@ if __name__ == "__main__":
config.port=args.port
LOLLMSWebUI.build_instance(config=config, lollms_paths=lollms_paths, socketio=sio)
lollmsElfServer = LOLLMSWebUI.get_instance()
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
# Import all endpoints
from lollms.server.endpoints.lollms_binding_files_server import router as lollms_binding_files_server_router
from lollms.server.endpoints.lollms_infos import router as lollms_infos_router
@ -108,4 +110,33 @@ if __name__ == "__main__":
app = ASGIApp(socketio_server=sio, other_asgi_app=app)
uvicorn.run(app, host=config.host, port=6523)#config.port)
# if autoshow
if config.auto_show_browser:
if config['host']=="0.0.0.0":
#webbrowser.open(f"http://localhost:{config['port']}")
webbrowser.open(f"http://localhost:{6523}") # needed for debug (to be removed in production)
else:
#webbrowser.open(f"http://{config['host']}:{config['port']}")
webbrowser.open(f"http://{config['host']}:{6523}") # needed for debug (to be removed in production)
try:
sio.reboot = False
uvicorn.run(app, host=config.host, port=6523)#config.port)
if sio.reboot:
ASCIIColors.info("")
ASCIIColors.info("")
ASCIIColors.info("")
ASCIIColors.info(" ╔══════════════════════════════════════════════════╗")
ASCIIColors.info(" ║ Restarting backend ║")
ASCIIColors.info(" ╚══════════════════════════════════════════════════╝")
ASCIIColors.info("")
ASCIIColors.info("")
ASCIIColors.info("")
lollmsElfServer.run_restart_script(args)
except Exception as ex:
trace_exception(ex)

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
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-46f88ef1.js"></script>
<link rel="stylesheet" href="/assets/index-27a6ba78.css">
<script type="module" crossorigin src="/assets/index-db831b95.js"></script>
<link rel="stylesheet" href="/assets/index-d5a593e6.css">
</head>
<body>
<div id="app"></div>

View File

@ -184,7 +184,7 @@
</div>
</div>
<div class="mb-2" v-for="item in vramUsage.gpus">
<div class="mb-2" v-for="item in vramUsage.gpus" :key="item">
<label class="flex items-center gap-1 ml-2 mb-2 text-sm font-medium text-gray-900 dark:text-white">
<!-- GPU IMAGE -->
<img :src="SVGGPU" width="25" height="25">
@ -2438,8 +2438,6 @@ export default {
},
async getVramUsage() {
const resp = await this.api_get_req("vram_usage")
},
async progressListener(response) {
// does not work Still freezes UI
@ -2642,7 +2640,7 @@ export default {
this.is_loading_zoo = false
})
self.updateModelsZoo()
api_get_req("get_model_status").then((res)=>{
this.api_get_req("get_model_status").then((res)=>{
this.$store.commit('setIsModelOk', res);
})
}else{
@ -2892,7 +2890,7 @@ export default {
this.update_binding(binding_object.binding.folder)
this.binding_changed = true;
}
api_get_req("get_model_status").then((res)=>{
this.api_get_req("get_model_status").then((res)=>{
this.$store.commit('setIsModelOk', res);
})
},
@ -3223,13 +3221,13 @@ export default {
this.showAccordion = !this.showAccordion;
},
async update_setting(setting_name_val, setting_value_val, next) {
console.log("Updating setting", setting_name_val, ":", setting_value_val)
this.isLoading = true
const obj = {
setting_name: setting_name_val,
setting_value: setting_value_val
}
console.log("Updating setting", setting_name_val, ":", setting_value_val)
let res = await axios.post('/update_setting', obj)
if (res) {