Merge branch 'main' into drop-box

This commit is contained in:
AndzejsP 2023-05-30 13:30:38 +03:00
commit 4e38eddd3c
4 changed files with 32 additions and 47 deletions

45
app.py
View File

@ -288,7 +288,7 @@ class Gpt4AllWebUI(GPT4AllAPI):
config_data = yaml.load(config_file, Loader=yaml.FullLoader)
personality_info['name'] = config_data.get('name',"No Name")
personality_info['description'] = config_data.get('personality_description',"")
personality_info['author'] = config_data.get('creator', 'ParisNeo')
personality_info['author'] = config_data.get('author', 'ParisNeo')
personality_info['version'] = config_data.get('version', '1.0.0')
scripts_path = personality_folder / 'scripts'
personality_info['has_scripts'] = scripts_path.is_dir()
@ -390,49 +390,10 @@ class Gpt4AllWebUI(GPT4AllAPI):
self.config["language"]=data['setting_value']
elif setting_name== "personality_language":
back_language = self.config["personality_language"]
if self.config["personality_language"]!=data['setting_value']:
self.config["personality_language"]=data['setting_value']
personalities_categories_dir = Path(f'./personalities/{self.config["personality_language"]}') # replace with the actual path to the models folder
cats = [f.stem for f in personalities_categories_dir.iterdir() if f.is_dir()]
if len(cats)>0:
back_category = self.config["personality_category"]
self.config["personality_category"]=cats[0]
try:
personalities_dir = Path(f'./personalities/{self.config["personality_language"]}/{self.config["personality_category"]}') # replace with the actual path to the models folder
pers = [f.stem for f in personalities_dir.iterdir() if f.is_dir()]
except Exception as ex:
pers=[]
if self.config["debug"]:
print(f"No personalities found. Using default one {ex}")
if len(pers)>0:
self.config["personality"]=pers[0]
personality_fn = f"personalities/{self.config['personality_language']}/{self.config['personality_category']}/{self.config['personality']}"
self.personality.load_personality(personality_fn)
else:
self.config["personality"]=""
self.personality = AIPersonality()
self.config["personality_language"]=data['setting_value']
elif setting_name== "personality_category":
back_category = self.config["personality_category"]
if self.config["personality_category"]!=data['setting_value']:
self.config["personality_category"]=data['setting_value']
pers = json.loads(self.list_personalities().data.decode("utf8"))
if len(pers)>0:
self.config["personality"]=pers[0]
personality_fn = f"personalities/{self.config['personality_language']}/{self.config['personality_category']}/{self.config['personality']}"
try:
self.personality.load_personality(personality_fn)
if self.config["debug"]:
print(self.personality)
except:
print(f"couldn't load personality from {personality_fn}")
return jsonify({'setting_name': data['setting_name'], "status":False})
else:
self.config["personality_category"]=back_category
return jsonify({'setting_name': data['setting_name'], "status":False})
self.config["personality_category"]=data['setting_value']
elif setting_name== "personality":
self.config["personality"]=data['setting_value']
personality_fn = f"personalities/{self.config['personality_language']}/{self.config['personality_category']}/{self.config['personality']}"

View File

@ -14,3 +14,14 @@ python installations/download_all_personalities.py
rem Deactivate the virtual environment
echo deactivating
call %environment_name%\Scripts\deactivate.bat
rem Remove tmp folder
set "folder=tmp"
if exist "%folder%" (
echo Folder exists. Deleting...
rd /s /q "%folder%"
echo Folder deleted.
) else (
echo Folder does not exist.
)

View File

@ -9,11 +9,13 @@ def copy_files(source_path, destination_path):
if source_item.is_file():
# Remove destination file if it already exists
if destination_item.exists():
destination_item.unlink()
# Copy file from source to destination
shutil.copy2(str(source_item), str(destination_item))
try:
if destination_item.exists():
destination_item.unlink()
# Copy file from source to destination
shutil.copy2(str(source_item), str(destination_item))
except:
print(f"Couldn't install personality {item}")
elif source_item.is_dir():
# Create destination directory if it does not exist

View File

@ -14,3 +14,14 @@ python installations/download_all_personalities.py
# Deactivate the virtual environment
echo "deactivating"
deactivate
# Remove tmp folder
folder="tmp"
if [ -d "$folder" ]; then
echo "Folder exists. Deleting..."
rm -r "$folder"
echo "Folder deleted."
else
echo "Folder does not exist."
fi