mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-20 04:47:55 +00:00
Update app.py
This commit is contained in:
parent
060ea13b9c
commit
739a8b09e0
30
app.py
30
app.py
@ -1,7 +1,6 @@
|
|||||||
######
|
######
|
||||||
# Project : lollms-webui
|
# Project : lollms-webui
|
||||||
# Author : ParisNeo with the help of the community
|
# Author : ParisNeo with the help of the community
|
||||||
# Supported by Nomic-AI
|
|
||||||
# license : Apache 2.0
|
# license : Apache 2.0
|
||||||
# Description :
|
# Description :
|
||||||
# A front end Flask application for llamacpp models.
|
# A front end Flask application for llamacpp models.
|
||||||
@ -718,10 +717,10 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
personalities_folder = self.lollms_paths.personalities_zoo_path
|
personalities_folder = self.lollms_paths.personalities_zoo_path
|
||||||
personalities = {}
|
personalities = {}
|
||||||
|
|
||||||
for category_folder in personalities_folder.iterdir():
|
for category_folder in [self.lollms_paths.custom_personalities_path] + list(personalities_folder.iterdir()):
|
||||||
cat = category_folder.stem
|
cat = category_folder.stem
|
||||||
if category_folder.is_dir() and not category_folder.stem.startswith('.'):
|
if category_folder.is_dir() and not category_folder.stem.startswith('.'):
|
||||||
personalities[category_folder.name] = []
|
personalities[cat if category_folder!=self.lollms_paths.custom_personalities_path else "custom_personalities"] = []
|
||||||
for personality_folder in category_folder.iterdir():
|
for personality_folder in category_folder.iterdir():
|
||||||
pers = personality_folder.stem
|
pers = personality_folder.stem
|
||||||
if personality_folder.is_dir() and not personality_folder.stem.startswith('.'):
|
if personality_folder.is_dir() and not personality_folder.stem.startswith('.'):
|
||||||
@ -793,7 +792,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
else:
|
else:
|
||||||
personality_info['avatar'] = ""
|
personality_info['avatar'] = ""
|
||||||
|
|
||||||
personalities[category_folder.name].append(personality_info)
|
personalities[cat if category_folder!=self.lollms_paths.custom_personalities_path else "custom_personalities"].append(personality_info)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
ASCIIColors.warning(f"Couldn't load personality from {personality_folder} [{ex}]")
|
ASCIIColors.warning(f"Couldn't load personality from {personality_folder} [{ex}]")
|
||||||
trace_exception(ex)
|
trace_exception(ex)
|
||||||
@ -802,6 +801,9 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
def get_personality(self):
|
def get_personality(self):
|
||||||
category = request.args.get('category')
|
category = request.args.get('category')
|
||||||
name = request.args.get('name')
|
name = request.args.get('name')
|
||||||
|
if category == "custom_personalities":
|
||||||
|
personality_folder = self.lollms_paths.custom_personalities_path/f"{name}"
|
||||||
|
else:
|
||||||
personality_folder = self.lollms_paths.personalities_zoo_path/f"{category}"/f"{name}"
|
personality_folder = self.lollms_paths.personalities_zoo_path/f"{category}"/f"{name}"
|
||||||
personality_path = personality_folder/f"config.yaml"
|
personality_path = personality_folder/f"config.yaml"
|
||||||
personality_info = {}
|
personality_info = {}
|
||||||
@ -873,7 +875,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
self.config["active_personality_id"] = 0
|
self.config["active_personality_id"] = 0
|
||||||
self.config["personalities"][self.config["active_personality_id"]] = f"{self.personality_category}/{self.personality_name}"
|
self.config["personalities"][self.config["active_personality_id"]] = f"{self.personality_category}/{self.personality_name}"
|
||||||
|
|
||||||
if self.personality_category!="Custom":
|
if self.personality_category!="custom_personalities":
|
||||||
personality_fn = self.lollms_paths.personalities_zoo_path/self.config["personalities"][self.config["active_personality_id"]]
|
personality_fn = self.lollms_paths.personalities_zoo_path/self.config["personalities"][self.config["active_personality_id"]]
|
||||||
else:
|
else:
|
||||||
personality_fn = self.lollms_paths.personal_personalities_path/self.config["personalities"][self.config["active_personality_id"]].split("/")[-1]
|
personality_fn = self.lollms_paths.personal_personalities_path/self.config["personalities"][self.config["active_personality_id"]].split("/")[-1]
|
||||||
@ -1248,7 +1250,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
|
|
||||||
def list_personalities_categories(self):
|
def list_personalities_categories(self):
|
||||||
personalities_categories_dir = self.lollms_paths.personalities_zoo_path # replace with the actual path to the models folder
|
personalities_categories_dir = self.lollms_paths.personalities_zoo_path # replace with the actual path to the models folder
|
||||||
personalities_categories = [f.stem for f in personalities_categories_dir.iterdir() if f.is_dir() and not f.name.startswith(".")]
|
personalities_categories = ["custom_personalities"]+[f.stem for f in personalities_categories_dir.iterdir() if f.is_dir() and not f.name.startswith(".")]
|
||||||
return jsonify(personalities_categories)
|
return jsonify(personalities_categories)
|
||||||
|
|
||||||
def list_personalities(self):
|
def list_personalities(self):
|
||||||
@ -1256,6 +1258,9 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
if not category:
|
if not category:
|
||||||
return jsonify([])
|
return jsonify([])
|
||||||
try:
|
try:
|
||||||
|
if category=="custom_personalities":
|
||||||
|
personalities_dir = self.lollms_paths.custom_personalities_path # replace with the actual path to the models folder
|
||||||
|
else:
|
||||||
personalities_dir = self.lollms_paths.personalities_zoo_path/f'{category}' # replace with the actual path to the models folder
|
personalities_dir = self.lollms_paths.personalities_zoo_path/f'{category}' # replace with the actual path to the models folder
|
||||||
personalities = [f.stem for f in personalities_dir.iterdir() if f.is_dir() and not f.name.startswith(".")]
|
personalities = [f.stem for f in personalities_dir.iterdir() if f.is_dir() and not f.name.startswith(".")]
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
@ -1326,7 +1331,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
def delete_personality(self):
|
def delete_personality(self):
|
||||||
category = request.args.get('category')
|
category = request.args.get('category')
|
||||||
name = request.args.get('name')
|
name = request.args.get('name')
|
||||||
path = Path("personalities")/category/name
|
path = self.lollms_paths.personalities_zoo_path/category/name
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
return jsonify({'status':True})
|
return jsonify({'status':True})
|
||||||
@ -1386,6 +1391,9 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
|
|
||||||
|
|
||||||
def serve_personalities(self, filename):
|
def serve_personalities(self, filename):
|
||||||
|
if "custom_personalities" in filename:
|
||||||
|
path = str(self.lollms_paths.custom_personalities_path)
|
||||||
|
else:
|
||||||
path = str(self.lollms_paths.personalities_zoo_path/("/".join(filename.split("/")[:-1])))
|
path = str(self.lollms_paths.personalities_zoo_path/("/".join(filename.split("/")[:-1])))
|
||||||
|
|
||||||
fn = filename.split("/")[-1]
|
fn = filename.split("/")[-1]
|
||||||
@ -1805,7 +1813,11 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
language = data.get('language', None)
|
language = data.get('language', None)
|
||||||
|
|
||||||
package_path = f"{category}/{name}"
|
package_path = f"{category}/{name}"
|
||||||
|
if category=="custom_personalities":
|
||||||
|
package_full_path = self.lollms_paths.custom_personalities_path/f"{name}"
|
||||||
|
else:
|
||||||
package_full_path = self.lollms_paths.personalities_zoo_path/package_path
|
package_full_path = self.lollms_paths.personalities_zoo_path/package_path
|
||||||
|
|
||||||
config_file = package_full_path / "config.yaml"
|
config_file = package_full_path / "config.yaml"
|
||||||
if config_file.exists():
|
if config_file.exists():
|
||||||
if language:
|
if language:
|
||||||
@ -1863,7 +1875,11 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
|||||||
|
|
||||||
|
|
||||||
package_path = f"{category}/{name}"
|
package_path = f"{category}/{name}"
|
||||||
|
if category=="custom_personalities":
|
||||||
|
package_full_path = self.lollms_paths.custom_personalities_path/f"{name}"
|
||||||
|
else:
|
||||||
package_full_path = self.lollms_paths.personalities_zoo_path/package_path
|
package_full_path = self.lollms_paths.personalities_zoo_path/package_path
|
||||||
|
|
||||||
config_file = package_full_path / "config.yaml"
|
config_file = package_full_path / "config.yaml"
|
||||||
if config_file.exists():
|
if config_file.exists():
|
||||||
ASCIIColors.info(f"Unmounting personality {package_path}")
|
ASCIIColors.info(f"Unmounting personality {package_path}")
|
||||||
|
Loading…
Reference in New Issue
Block a user