diff --git a/app.py b/app.py index ec6602cd..2d3239e3 100644 --- a/app.py +++ b/app.py @@ -68,7 +68,24 @@ from api.config import load_config, save_config from api import LoLLMsAPPI import shutil import markdown +import socket +def get_ip_address(): + # Create a socket object + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + + try: + # Connect to a remote host (doesn't matter which one) + sock.connect(('8.8.8.8', 80)) + + # Get the local IP address of the socket + ip_address = sock.getsockname()[0] + return ip_address + except socket.error: + return None + finally: + # Close the socket + sock.close() class LoLLMsWebUI(LoLLMsAPPI): def __init__(self, _app, _socketio, config:LOLLMSConfig, config_file_path:Path|str, lollms_paths:LollmsPaths) -> None: @@ -1430,9 +1447,16 @@ if __name__ == "__main__": else: ASCIIColors.info("debug mode:false") - url = f'http://{config["host"]}:{config["port"]}' + + + + url = f'http://{config["host"]}:{config["port"]}' + if config["host"]=="0.0.0.0": + print(f'Please open your browser and go to http://localhost:{config["port"]} to view the ui') + ASCIIColors.success(f'This server is visible from a remote PC. use this address http://{get_ip_address()}:{config["port"]}') + else: + print(f"Please open your browser and go to {url} to view the ui") - print(f"Please open your browser and go to {url} to view the ui") socketio.run(app, host=config["host"], port=config["port"]) # http_server = WSGIServer((config["host"], config["port"]), app, handler_class=WebSocketHandler) # http_server.serve_forever() diff --git a/c_webui.bat b/c_webui.bat index a1286f97..4461959f 100644 --- a/c_webui.bat +++ b/c_webui.bat @@ -1,3 +1,4 @@ +@echo off echo \u001b[34m echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH @@ -35,9 +36,10 @@ echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH echo \u001b[0m -@echo off +echo Testing internet connection ping -n 1 google.com >nul +echo here if %errorlevel% equ 0 ( echo Internet Connection working fine @@ -78,24 +80,65 @@ if %errorlevel% equ 0 ( if %errorlevel% equ 0 ( echo Conda is installed ) else ( - set /p choice=Conda is not installed. Would you like to install Conda? [Y/N] + set /p choice="Conda is not installed. Would you like to install Conda? [Y/N]:" if /i "%choice%"=="Y" ( echo Installing Conda... - REM Replace the following lines with appropriate Conda installation commands for Windows - echo Please install Conda and try again. - exit /b 1 + set "miniconda_installer_url=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" + set "miniconda_installer=miniconda_installer_filename.exe" + rem Download the Miniconda installer using curl. + curl -o "%miniconda_installer%" "%miniconda_installer_url%" + if exist "%miniconda_installer%" ( + echo Miniconda installer downloaded successfully. + echo Installing Miniconda... + echo. + + rem Run the Miniconda installer. + "%miniconda_installer%" /InstallationType=JustMe /AddToPath=yes /RegisterPython=0 /S /D="%USERPROFILE%\Miniconda" + + if %errorlevel% equ 0 ( + echo Miniconda has been installed successfully in "%USERPROFILE%\Miniconda". + ) else ( + echo Failed to install Miniconda. + ) + + rem Clean up the Miniconda installer file. + del "%miniconda_installer%" + + rem Activate Miniconda. + call "%USERPROFILE%\Miniconda\Scripts\activate" + + ) else ( + echo Failed to download the Miniconda installer. + exit /b 1 + ) ) ) - REM Create a new Conda environment - echo Creating Conda environment... - conda create --prefix ./env python=3.10 + set "filename=./env" + echo Deactivating any activated environment + conda deactivate + + rem Check the error level to determine if the file exists + cd %filename% + IF !ERRORLEVEL! GTR 0 ( + REM Create a new Conda environment + echo Creating Conda environment... + conda create --prefix ./env python=3.10 + conda activate ./env + pip install --upgrade pip setuptools wheel + conda install -c conda-forge cudatoolkit-dev + ) else ( + echo %CD% + cd .. + echo Environment already exists. Skipping environment creation. + conda activate ./env + ) + echo Activating environment conda activate ./env echo Conda environment is created REM Install the required packages - echo Installing requirements... - pip install --upgrade pip setuptools wheel + echo Installing requirements using pip... pip install -r requirements.txt if %errorlevel% neq 0 ( @@ -108,7 +151,29 @@ if %errorlevel% equ 0 ( rmdir /s /q "./tmp" echo Cleaning tmp folder ) + + conda list | findstr /i /c:"cudatoolkit-dev" >nul + if errorlevel 1 ( + echo CUDA package not found. Installing... + set /p install_cuda=Do you want to install CUDA? (Y/N) + if /i "%install_cuda%"=="Y" ( + conda install -c conda-forge cudatoolkit-dev + ) + ) else ( + echo CUDA package is already installed. + ) + echo Launching application + REM Launch the Python application + python app.py + +) else ( + REM Go to webui folder + cd lollms-webui + + REM Activate environment + conda activate ./env + + REM Launch the Python application + python app.py ) -REM Launch the Python application -python app.py diff --git a/c_webui.sh b/c_webui.sh index 8c881757..3c55e872 100644 --- a/c_webui.sh +++ b/c_webui.sh @@ -111,7 +111,12 @@ if ping -q -c 1 google.com >/dev/null 2>&1; then rm -rf "./tmp" echo "Cleaning tmp folder" fi - + # Launch the Python application + python app.py +else + # go to the ui folder + cd lollms-webui + conda activate ./env + # Launch the Python application + python app.py fi -# Launch the Python application -python app.py diff --git a/docs/youtube/script_lollms.md b/docs/youtube/script_lollms.md index 4322cda4..b67b897f 100644 --- a/docs/youtube/script_lollms.md +++ b/docs/youtube/script_lollms.md @@ -12,4 +12,9 @@ The third use is by directly using out web-ui to interact with the language mode The web-ui has multiple functionalities and allow you to handle many tasks. Now let's install the application. -As usual, go to +To install the application, you need to have already installed git and python 3.10 with its pip package manager. You can optionally have anaconda or miniconda installed if you want to use that option. To use the GPU, you also need to install Cuda toolkit v 11.7 or higher or use the conda installation script that will automatically install conda build tools. Make sure git, python and cuda are added to your path environment variable and let's begin. +As usual, go to the github repository then to the release page. Now you have many options depending on your system and your preference. for windows, you can use webui.bat or c_webui.bat, for linux, you can use webui.sh or c-webui.sh. C stands for conda, so if you havn't installed conda, don't use that file. + +Download the file to a folder where you want to install the application. + +Once it is downloaded, go to the folder and double click the script to run it. \ No newline at end of file diff --git a/webui.bat b/webui.bat index 665366c2..48cdea83 100644 --- a/webui.bat +++ b/webui.bat @@ -183,7 +183,10 @@ powershell -Command "Invoke-WebRequest -Uri 'https://bootstrap.pypa.io/get-pip.p REM Install pip echo Installing pip... python tmp/get-pip.py - +REM Upgrading pip setuptools and wheel +echo Updating pip setuptools and wheel +python -m pip install --upgrade pip setuptools wheel +goto PIP_SKIP :PIP_CANCEL echo Please install pip and try again. pause @@ -191,10 +194,6 @@ exit /b 1 :PIP_SKIP -REM Upgrading pip setuptools and wheel -echo Updating pip setuptools and wheel -python -m pip install --upgrade pip setuptools wheel - REM Check if pip is installed set /p="Checking for virtual environment..." nul 2>&1