fixed bugs

This commit is contained in:
Saifeddine ALOUI 2024-05-04 23:57:05 +02:00
parent ec5428c68f
commit 6ae2600aa4
18 changed files with 105 additions and 135 deletions

View File

@ -87,7 +87,7 @@ xtts_use_deepspeed: false
xtts_use_streaming_mode: true
auto_read: false
current_voice: null
current_language: en
xtts_current_language: en
# Image generation service
enable_sd_service: false

View File

@ -82,7 +82,7 @@ enable_voice_service: false
xtts_base_url: http://localhost:8020
auto_read: false
current_voice: null
current_language: en
xtts_current_language: en
# Image generation service
enable_sd_service: false

View File

@ -82,7 +82,7 @@ enable_voice_service: false
xtts_base_url: http://localhost:8020
auto_read: false
current_voice: null
current_language: en
xtts_current_language: en
# Image generation service
enable_sd_service: false

View File

@ -82,7 +82,7 @@ enable_voice_service: false
xtts_base_url: http://localhost:8020
auto_read: false
current_voice: null
current_language: en
xtts_current_language: en
# Image generation service
enable_sd_service: false

View File

@ -353,28 +353,7 @@ class LollmsApplication(LoLLMsCom):
self.cancel_gen = False
ASCIIColors.warning("Generation canceled")
return False
def learn_from_discussion(self, title, discussion, nb_gen=None, callback=None):
if self.config.summerize_discussion:
prompt = f"!@>discussion:\n--\n!@>title:{title}!@>content:\n{discussion}\n--\n!@>question:What should we learn from this discussion?!@>Summerizer: Here is a summary of the most important informations extracted from the discussion:\n"
if nb_gen is None:
nb_gen = self.config.max_summary_size
generated = ""
gen_infos={
"nb_received_tokens":0,
"generated_text":"",
"processing":False,
"first_chunk": True,
}
if callback is None:
callback = partial(self.default_callback, generation_infos=gen_infos)
self.model.generate(prompt, nb_gen, callback)
if self.config.debug:
ASCIIColors.yellow(gen_infos["generated_text"])
return gen_infos["generated_text"]
else:
return discussion
def remove_text_from_string(self, string, text_to_find):
"""
Removes everything from the first occurrence of the specified text in the string (case-insensitive).
@ -679,7 +658,7 @@ class LollmsApplication(LoLLMsCom):
else:
conditionning = self.personality._personality_conditioning
conditionning = self.personality.replace_keys(conditionning, self.personality.conditionning_commands)
conditionning = self.personality.replace_keys(conditionning, self.personality.conditionning_commands) +"" if conditionning[-1]=="\n" else "\n"
# Check if there are document files to add to the prompt
internet_search_results = ""

View File

@ -87,7 +87,7 @@ xtts_use_deepspeed: false
xtts_use_streaming_mode: true
auto_read: false
current_voice: null
current_language: en
xtts_current_language: en
# Image generation service
enable_sd_service: false

View File

@ -87,7 +87,7 @@ xtts_use_deepspeed: false
xtts_use_streaming_mode: true
auto_read: false
current_voice: null
current_language: en
xtts_current_language: en
# Image generation service
enable_sd_service: false

View File

@ -146,6 +146,19 @@ async def apply_settings(request: Request):
:param request: The HTTP request object.
:return: A JSON response with the status of the operation.
"""
path_traversal_prone_settings=[
"binding_name",
"model_name",
"model_variant",
"app_custom_logo",
"user_avatar",
"debug_log_file_path",
"petals_model_path",
"skills_lib_database_name",
"discussion_db_name"
"user_avatar",
]
# Prevent all outsiders from sending something to this endpoint
forbid_remote_access(lollmsElfServer)
if lollmsElfServer.config.turn_on_setting_update_validation:
@ -167,6 +180,8 @@ async def apply_settings(request: Request):
if key=="turn_on_setting_update_validation" and lollmsElfServer.config.config[key]==True and config.get(key, lollmsElfServer.config.config[key])==False:
if not show_yes_no_dialog("WARNING!!!","I received a request to deactivate settings update validation.\nAre you sure?\nThis is a very risky decision, especially if you have enabled remote access.\nDisabling this validation can allow attackers to manipulate server settings and gain unauthorized access.\nProceed only if you are completely confident in the security of your system.\nDo you want to continue despite the warning?"):
config["turn_on_setting_update_validation"]=False
if key in path_traversal_prone_settings:
config[key]=sanitize_path(config.get(key, lollmsElfServer.config.config[key]))
lollmsElfServer.config.config[key] = config.get(key, lollmsElfServer.config.config[key])
ASCIIColors.success("OK")

View File

@ -89,6 +89,8 @@ def get_model_status():
def add_reference_to_local_model(data:ModelReferenceParams):
forbid_remote_access(lollmsElfServer)
data.path = sanitize_path(data.path, allow_absolute_path=True)
if data.path=="":
return {"status": False, "error":"Empty model path"}

View File

@ -55,6 +55,7 @@ def switch_personal_path(data:PersonalPathParameters):
@router.post("/upload_avatar")
@router.post("/upload_logo")
async def upload_avatar(avatar: UploadFile = File(...)):
"""
Uploads a user avatar file to a dedicated directory, preventing path traversal attacks.

View File

@ -160,6 +160,7 @@ def install_xtts():
lollmsElfServer.HideBlockingMessage()
return {"status":True}
except Exception as ex:
trace_exception(ex)
lollmsElfServer.HideBlockingMessage()
return {"status":False, 'error':str(ex)}
@ -178,6 +179,7 @@ def start_xtts():
)
lollmsElfServer.HideBlockingMessage()
except Exception as ex:
trace_exception(ex)
lollmsElfServer.HideBlockingMessage()
return {"url": None, "error":f"{ex}"}

View File

@ -29,7 +29,7 @@ from typing import List, Dict, Any
from ascii_colors import ASCIIColors, trace_exception
from lollms.paths import LollmsPaths
from lollms.utilities import git_pull, show_yes_no_dialog, run_python_script_in_env, create_conda_env, run_pip_in_env
from lollms.utilities import git_pull, show_yes_no_dialog, run_python_script_in_env, create_conda_env, run_pip_in_env, environment_exists
import subprocess
import platform
@ -37,29 +37,51 @@ def verify_xtts(lollms_paths:LollmsPaths):
# Clone repository
root_dir = lollms_paths.personal_path
shared_folder = root_dir/"shared"
xtts_folder = shared_folder / "xtts"
return xtts_folder.exists()
xtts_path = shared_folder / "xtts"
return xtts_path.exists()
def install_xtts(lollms_app:LollmsApplication):
ASCIIColors.green("XTTS installation started")
repo_url = "https://github.com/ParisNeo/xtts-api-server"
root_dir = lollms_app.lollms_paths.personal_path
shared_folder = root_dir/"shared"
xtts_folder = shared_folder / "xtts"
if xtts_folder.exists() and PackageManager.check_package_installed("xtts-api-server"):
if not show_yes_no_dialog("warning!","It looks like xtts is already installed on your system.\nDo you want to reinstall it?"):
lollms_app.error("Service installation canceled")
return
lollms_app.ShowBlockingMessage("Creating xtts environment")
ASCIIColors.cyan("Installing autosd conda environment with python 3.10")
create_conda_env("xtts","3.10")
xtts_path = shared_folder / "xtts"
# Step 1: Clone or update the repository
if os.path.exists(xtts_path):
print("Repository already exists. Pulling latest changes...")
try:
subprocess.run(["git", "-C", xtts_path, "pull"], check=True)
except:
subprocess.run(["git", "clone", repo_url, xtts_path], check=True)
else:
print("Cloning repository...")
subprocess.run(["git", "clone", repo_url, xtts_path], check=True)
# Step 2: Create or update the Conda environment
if environment_exists("xtts"):
print("Conda environment 'xtts' already exists. Updating...")
# Here you might want to update the environment, e.g., update Python or dependencies
# This step is highly dependent on how you manage your Conda environments and might involve
# running `conda update` commands or similar.
else:
print("Creating Conda environment 'xtts'...")
create_conda_env("xtts", "3.8")
# Step 3: Install or update dependencies using your custom function
requirements_path = os.path.join(xtts_path, "requirements.txt")
run_pip_in_env("xtts", f"install -r {requirements_path}", cwd=xtts_path)
run_pip_in_env("xtts", f"install torch==2.1.1+cu118 torchaudio==2.1.1+cu118 --index-url https://download.pytorch.org/whl/cu118", cwd=xtts_path)
# Step 4: Launch the server
# Assuming the server can be started with a Python script in the cloned repository
print("Launching XTTS API server...")
run_python_script_in_env("xtts", "xtts_api_server", cwd=xtts_path)
print("XTTS API server setup and launch completed.")
ASCIIColors.cyan("Done")
ASCIIColors.cyan("Installing xtts-api-server")
run_pip_in_env("xtts", "install --upgrade xtts-api-server")
run_pip_in_env("xtts", "install --upgrade torchaudio==2.1.1+cu118 --index-url https://download.pytorch.org/whl/cu118")
ASCIIColors.cyan("Done")
xtts_folder.mkdir(exist_ok=True,parents=True)
ASCIIColors.green("XTTS server installed successfully")
@ -67,9 +89,9 @@ def install_xtts(lollms_app:LollmsApplication):
def get_xtts(lollms_paths:LollmsPaths):
root_dir = lollms_paths.personal_path
shared_folder = root_dir/"shared"
xtts_folder = shared_folder / "xtts"
xtts_script_path = xtts_folder / "lollms_xtts.py"
git_pull(xtts_folder)
xtts_path = shared_folder / "xtts"
xtts_script_path = xtts_path / "lollms_xtts.py"
git_pull(xtts_path)
if xtts_script_path.exists():
ASCIIColors.success("lollms_xtts found.")
@ -113,7 +135,7 @@ class LollmsXTTS:
self.auto_xtts_url = self.xtts_base_url+"/sdapi/v1"
shared_folder = root_dir/"shared"
self.xtts_folder = shared_folder / "xtts"
self.xtts_path = shared_folder / "xtts"
ASCIIColors.red(" __ ___ __ __ __ __ ___ _ ")
ASCIIColors.red(" / / /___\/ / / / /\/\ / _\ \ \/ / |_| |_ ___ ")

View File

@ -1,43 +0,0 @@
@echo off
set MINICONDA_DIR=%cd%\installer_files\miniconda3
set INSTALL_ENV_DIR=%cd%\installer_files\xtts
:: Check if portable Conda is installed
IF EXIST "%MINICONDA_DIR%\Scripts\activate.bat" (
echo "Using portable Conda installation."
echo "%MINICONDA_DIR%"
@rem create the installer env
if exist "%INSTALL_ENV_DIR%" (
echo "found"
rmdir "%INSTALL_ENV_DIR%" /s /q
)
echo Packages to install: %PACKAGES_TO_INSTALL%
call conda create --no-shortcuts -y -k -p "%INSTALL_ENV_DIR%" || ( echo. && echo Conda environment creation failed. && goto end )
@rem activate miniconda
call "%MINICONDA_DIR%\Scripts\activate.bat" || ( echo Miniconda hook not found. && goto end )
call "%MINICONDA_DIR%\Scripts\pip.exe" install xtts-api-server
) else (
echo "No portable Conda found. Checking for system-wide Conda installation."
where conda >nul 2>&1
if %errorlevel% == 0 (
echo "Using system-wide Conda installation."
call conda deactivate
call conda info --envs | findstr /B /C:"xtts" >nul 2>&1
if %errorlevel% == 0 (
echo "Conda environment 'xtts' already exists. Deleting it."
call conda env remove --name xtts --yes
)
call conda create --name xtts --yes
call conda activate xtts
call pip install xtts-api-server
) else (
echo "No Conda installation found. Please install Conda."
exit /b 1
)
)
echo "Done"
exit /b

View File

@ -1,3 +0,0 @@
conda create --name xtts
conda activate xtts
pip install xtts-api-server

View File

@ -1,28 +0,0 @@
@echo off
set MINICONDA_DIR=%cd%\installer_files\miniconda3
set INSTALL_ENV_DIR=%cd%\installer_files\xtts
:: Check if portable Conda is installed
IF EXIST ".\installer_files\miniconda3\Scripts\activate.bat" (
echo "Using portable Conda installation."
@rem activate miniconda
call "%MINICONDA_DIR%\Scripts\activate.bat" || ( echo Miniconda hook not found. && goto end )
@rem activate installer env
call conda activate "%INSTALL_ENV_DIR%" || ( echo. && echo Conda environment activation failed. && goto end )
call .\installer_files\miniconda3\Scripts\activate.bat xtts
call .\installer_files\miniconda3\python.exe -m xtts_api_server -o %1 -sf %2
exit /b
) else (
echo "No portable Conda found. Checking for system-wide Conda installation."
where conda >nul 2>&1
if %errorlevel% == 0 (
echo "Using system-wide Conda installation."
call conda activate xtts
python -m xtts_api_server -o %1 -sf %2
exit /b
) else (
echo "No Conda installation found. Please install Conda."
exit /b 1
)
)
exit /b

View File

@ -1,3 +0,0 @@
#!/bin/bash
conda activate xtts
conda activate xtts && python -m xtts_api_server -o %1 -sf %2

View File

@ -114,6 +114,39 @@ def run_script_in_env(env_name, script_path, cwd=None):
ASCIIColors.yellow(python_path)
#run_command(Commands.RUN, "-n", env_name, str(script_path), cwd=cwd)
def get_conda_path():
import platform
if platform.system() == "Windows":
return Path(sys.executable).parent.parent / "miniconda3" / "condabin" / "conda"
else:
return Path(sys.executable).parent.parent.parent / "miniconda3" / "bin" / "conda"
def environment_exists(env_name):
env_name = sanitize_shell_code(env_name)
conda_path = get_conda_path()
result = subprocess.run(f'{conda_path} env list --json', shell=True, capture_output=True, text=True)
envs_info = json.loads(result.stdout)
env_names = [Path(env).name for env in envs_info['envs']]
return env_name in env_names
def get_python_version(env_name):
env_name = sanitize_shell_code(env_name)
conda_path = get_conda_path()
if environment_exists(env_name):
result = subprocess.run(f'{conda_path} run -n {env_name} python --version', shell=True, capture_output=True, text=True)
return result.stdout.strip()
else:
return "Environment does not exist."
def remove_environment(env_name):
env_name = sanitize_shell_code(env_name)
conda_path = get_conda_path()
if environment_exists(env_name):
process = subprocess.Popen(f'{conda_path} env remove --name {env_name} -y', shell=True)
process.wait()
return f"Environment '{env_name}' has been removed."
else:
return "Environment does not exist."
def process_ai_output(output, images, output_folder):
if not PackageManager.check_package_installed("cv2"):
@ -181,13 +214,6 @@ def discussion_path_2_url(path:str|Path):
path = str(path)
return path[path.index('discussion_databases'):].replace('discussion_databases','discussions')
def get_conda_path():
# Get the path to the Python executable that's running the script
python_executable_path = sys.executable
# Construct the path to the 'conda' executable based on the Python executable path
# Assuming that 'conda' is in the same directory as the Python executable
conda_executable_path = os.path.join(os.path.dirname(python_executable_path), 'conda')
return conda_executable_path
def yes_or_no_input(prompt):
while True:

View File

@ -82,7 +82,7 @@ enable_voice_service: false
xtts_base_url: http://localhost:8020
auto_read: false
current_voice: null
current_language: en
xtts_current_language: en
# Image generation service
enable_sd_service: false