fixed conda stuff

This commit is contained in:
Saifeddine ALOUI 2024-03-18 00:22:59 +01:00
parent 8f7101bcdc
commit e16f61bc19
4 changed files with 38 additions and 14 deletions

View File

@ -236,7 +236,7 @@ class LollmsApplication(LoLLMsCom):
if self.config.enable_comfyui_service:
try:
from lollms.services.comfyui.lollms_comfyui import LollmsComfyUI
self.comfyui = LollmsComfyUI(self, auto_comfyui_base_url=self.config.comfyui_base_url)
self.comfyui = LollmsComfyUI(self, comfyui_base_url=self.config.comfyui_base_url)
except:
self.warning(f"Couldn't load SD")

View File

@ -44,7 +44,7 @@ def install_comfyui():
return {"status":True}
except Exception as ex:
lollmsElfServer.HideBlockingMessage()
lollmsElfServer.InfoMessage(f"It looks like I could not install Comfyui because of this error:\n{ex}\nThis is commonly caused by a previous version that I couldn't delete. PLease remove {lollmsElfServer.lollms_paths.personal_path}/shared/auto_comfyui manually then try again")
lollmsElfServer.InfoMessage(f"It looks like I could not install Comfyui because of this error:\n{ex}\nThis is commonly caused by a previous version that I couldn't delete. PLease remove {lollmsElfServer.lollms_paths.personal_path}/shared/comfyui manually then try again")
return {"status":False, 'error':str(ex)}
@router.get("/start_comfyui")
@ -64,7 +64,7 @@ def start_comfyui():
return {"status":True}
except Exception as ex:
lollmsElfServer.HideBlockingMessage()
lollmsElfServer.InfoMessage(f"It looks like I could not install SD because of this error:\n{ex}\nThis is commonly caused by a previous version that I couldn't delete. PLease remove {lollmsElfServer.lollms_paths.personal_path}/shared/auto_comfyui manually then try again")
lollmsElfServer.InfoMessage(f"It looks like I could not install SD because of this error:\n{ex}\nThis is commonly caused by a previous version that I couldn't delete. PLease remove {lollmsElfServer.lollms_paths.personal_path}/shared/comfyui manually then try again")
return {"status":False, 'error':str(ex)}
@router.get("/show_comfyui")

View File

@ -73,17 +73,17 @@ def install_comfyui(lollms_app:LollmsApplication):
return
subprocess.run(["git", "clone", "https://github.com/ParisNeo/ComfyUI.git", str(comfyui_folder)])
subprocess.run(["git", "clone", "https://github.com/ParisNeo/ComfyUI-Manager.git", str(comfyui_folder/"custom_nodes")])
subprocess.run(["git", "clone", "https://github.com/ParisNeo/ComfyUI-Manager.git", str(comfyui_folder/"custom_nodes/ComfyUI-Manager")])
if show_yes_no_dialog("warning!","Do you want to install a model from civitai?\nIsuggest dreamshaper xl."):
download_file("https://civitai.com/api/download/models/351306", comfyui_folder/"models/checkpoints","dreamshaperXL_v21TurboDPMSDE.safetensors")
create_conda_env("comfyui","3.10")
if lollms_app.config.hardware_mode in ["nvidia", "nvidia-tensorcores"]:
run_script_in_env("comfyui", "pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121")
run_python_script_in_env("comfyui", "-m pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121")
if lollms_app.config.hardware_mode in ["amd", "amd-noavx"]:
run_script_in_env("comfyui", "pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.7")
run_python_script_in_env("comfyui", "-m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.7")
elif lollms_app.config.hardware_mode in ["cpu", "cpu-noavx"]:
run_script_in_env("comfyui", "pip install --pre torch torchvision torchaudio")
run_script_in_env("comfyui", f"pip install -r {comfyui_folder}/requirements.txt")
run_python_script_in_env("comfyui", "-m pip install --pre torch torchvision torchaudio")
run_python_script_in_env("comfyui", f"-m pip install -r {comfyui_folder}/requirements.txt")
lollms_app.comfyui = LollmsComfyUI(lollms_app)
ASCIIColors.green("Comfyui installed successfully")
@ -93,11 +93,11 @@ def get_comfyui(lollms_paths:LollmsPaths):
root_dir = lollms_paths.personal_path
shared_folder = root_dir/"shared"
comfyui_folder = shared_folder / "comfyui"
comfyui_script_path = comfyui_folder / "lollms_comfyui.py"
comfyui_script_path = comfyui_folder / "main.py"
git_pull(comfyui_folder)
if comfyui_script_path.exists():
ASCIIColors.success("lollms_comfyui found.")
ASCIIColors.success("comfyui found.")
ASCIIColors.success("Loading source file...",end="")
# use importlib to load the module from the file path
from lollms.services.comfyui.lollms_comfyui import LollmsComfyUI

View File

@ -42,27 +42,51 @@ import subprocess
from functools import partial
def create_conda_env(env_name, python_version):
from conda.cli.python_api import run_command, Commands
# Activate the Conda environment
import platform
if platform.system()=="Windows":
conda_path = Path(sys.executable).parent.parent/"miniconda3"/"condabin"/"conda"
else:
conda_path = Path(sys.executable).parent.parent/"miniconda3"/"bin"/"conda"
process = subprocess.Popen(f'{conda_path} create --name {env_name} python={python_version} -y', shell=True)
# Wait for the process to finish
process.wait()
#from conda.cli.python_api import run_command, Commands
# Create a new Conda environment with the specified Python version
run_command(Commands.CREATE, "-n", env_name, f"python={python_version}")
#run_command(Commands.CREATE, "-n", env_name, f"python={python_version}")
def run_python_script_in_env(env_name, script_path, cwd=None):
from conda.cli.python_api import run_command, Commands
import platform
# Set the current working directory if provided, otherwise use the current directory
if cwd is None:
cwd = os.getcwd()
# Activate the Conda environment
run_command(Commands.RUN, "-n", env_name, "python", str(script_path), cwd=cwd)
python_path = Path(sys.executable).parent.parent/"miniconda3"/"envs"/env_name/"python"
process = subprocess.Popen(f'{python_path} {script_path}', shell=True)
# Wait for the process to finish
process.wait()
#subprocess.Popen(f'conda activate {env_name} && {script_path}', shell=True, cwd=cwd)
#run_command(Commands.RUN, "-n", env_name, "python " + str(script_path), cwd=cwd)
def run_script_in_env(env_name, script_path, cwd=None):
from conda.cli.python_api import run_command, Commands
import platform
# Set the current working directory if provided, otherwise use the current directory
if cwd is None:
cwd = os.path.dirname(script_path)
# Activate the Conda environment
subprocess.Popen(f'conda activate {env_name} && {script_path}', shell=True, cwd=cwd)
if platform.system()=="Windows":
python_path = Path(sys.executable).parent.parent/"miniconda3"/"condabin"/"python"
else:
python_path = Path(sys.executable).parent.parent/"miniconda3"/"bin"/"python"
# Activate the Conda environment
subprocess.Popen(f'{python_path} activate {env_name} && {script_path}', shell=True, cwd=cwd)
#run_command(Commands.RUN, "-n", env_name, str(script_path), cwd=cwd)