Inhanced model installation, Working hugging face binding

This commit is contained in:
Saifeddine ALOUI 2023-08-23 17:59:52 +02:00
parent 1c80ba41b4
commit a6deac5f9c
3 changed files with 144 additions and 119 deletions

3
.gitignore vendored
View File

@ -203,3 +203,6 @@ src/taming-transformers
# Temporary arguments to restart file # Temporary arguments to restart file
temp_args.txt temp_args.txt
# Hugging face offloading folder
offload

View File

@ -223,6 +223,7 @@ class LoLLMsAPPI(LollmsApplication):
binding_folder = self.config["binding_name"] binding_folder = self.config["binding_name"]
model_url = model_path model_url = model_path
signature = f"{model_name}_{binding_folder}_{model_url}" signature = f"{model_name}_{binding_folder}_{model_url}"
try:
self.download_infos[signature]={ self.download_infos[signature]={
"start_time":datetime.now(), "start_time":datetime.now(),
"total_size":self.binding.get_file_size(model_path), "total_size":self.binding.get_file_size(model_path),
@ -233,10 +234,10 @@ class LoLLMsAPPI(LollmsApplication):
} }
if installation_path.exists(): if installation_path.exists():
print("Error: Model already exists") print("Error: Model already exists. please remove it first")
socketio.emit('install_progress',{ socketio.emit('install_progress',{
'status': False, 'status': False,
'error': 'model already exists', 'error': f'model already exists. Please remove it first.\nThe model can be found here:{installation_path}',
'model_name' : model_name, 'model_name' : model_name,
'binding_folder' : binding_folder, 'binding_folder' : binding_folder,
'model_url' : model_url, 'model_url' : model_url,
@ -293,6 +294,7 @@ class LoLLMsAPPI(LollmsApplication):
self.binding.download_model(model_path, installation_path, callback) self.binding.download_model(model_path, installation_path, callback)
except Exception as ex: except Exception as ex:
ASCIIColors.warning(str(ex)) ASCIIColors.warning(str(ex))
trace_exception(ex)
socketio.emit('install_progress',{ socketio.emit('install_progress',{
'status': False, 'status': False,
'error': 'canceled', 'error': 'canceled',
@ -318,6 +320,7 @@ class LoLLMsAPPI(LollmsApplication):
self.download_file(model_path, installation_path, callback) self.download_file(model_path, installation_path, callback)
except Exception as ex: except Exception as ex:
ASCIIColors.warning(str(ex)) ASCIIColors.warning(str(ex))
trace_exception(ex)
socketio.emit('install_progress',{ socketio.emit('install_progress',{
'status': False, 'status': False,
'error': 'canceled', 'error': 'canceled',
@ -347,7 +350,21 @@ class LoLLMsAPPI(LollmsApplication):
'speed': self.download_infos[signature]['speed'], 'speed': self.download_infos[signature]['speed'],
}, room=room_id) }, room=room_id)
del self.download_infos[signature] del self.download_infos[signature]
except Exception as ex:
trace_exception(ex)
socketio.emit('install_progress',{
'status': False,
'error': str(ex),
'model_name' : model_name,
'binding_folder' : binding_folder,
'model_url' : model_url,
'start_time': '',
'total_size': 0,
'downloaded_size': 0,
'progress': 0,
'speed': 0,
}, room=room_id
)
tpe = threading.Thread(target=install_model_, args=()) tpe = threading.Thread(target=install_model_, args=())
tpe.start() tpe.start()

5
app.py
View File

@ -1646,6 +1646,11 @@ class LoLLMsWebUI(LoLLMsAPPI):
path = f'{server}{filename}' path = f'{server}{filename}'
else: else:
path = f'{server}/{filename}' path = f'{server}/{filename}'
blocs = filename.split("/")
# Special case, if hugging face model format
if len(blocs)==2:
filename = blocs[1]
local_path = lollms_paths.personal_models_path/f'{self.config["binding_name"]}/{filename}' local_path = lollms_paths.personal_models_path/f'{self.config["binding_name"]}/{filename}'
is_installed = local_path.exists() or model_type.lower()=="api" is_installed = local_path.exists() or model_type.lower()=="api"
models.append({ models.append({