162 lines
3.0 KiB
Bash
Executable File
162 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# https://stackoverflow.com/a/1482133
|
|
SCRIPT_DIR="$(dirname -- "$(readlink -f -- "$0";)";)"
|
|
cd "${SCRIPT_DIR}"
|
|
|
|
if [[ -f config_example.sh ]]; then source config_example.sh; fi
|
|
if [[ -f config.sh ]]; then source config.sh; fi
|
|
|
|
#
|
|
#
|
|
#
|
|
#
|
|
#
|
|
#
|
|
#
|
|
|
|
function title()
|
|
{
|
|
echo -ne "\033]0;$@\007"
|
|
}
|
|
|
|
if [[ ! -d venv ]]
|
|
then
|
|
python3 -m venv venv || python -m venv venv || (
|
|
echo "Could not make a python virtual environment"
|
|
exit 1
|
|
)
|
|
|
|
FIRST_RUN=1
|
|
fi
|
|
|
|
if [[ -f ./venv/bin/activate ]]; then source ./venv/bin/activate; fi
|
|
if [[ -f ./venv/Scripts/activate ]]; then source ./venv/Scripts/activate; IS_WINDOWS=1; fi
|
|
|
|
if [[ -f ./python/python.exe ]]
|
|
then
|
|
IS_WINDOWS=1
|
|
|
|
function pip()
|
|
{
|
|
./python/python.exe -m pip "$@"
|
|
}
|
|
|
|
function python()
|
|
{
|
|
./python/python.exe "$@"
|
|
}
|
|
|
|
function streamlit()
|
|
{
|
|
./python/Scripts/streamlit.exe "$@"
|
|
}
|
|
|
|
export -f pip
|
|
export -f streamlit
|
|
export -f python
|
|
fi
|
|
|
|
PYTHON="python3"
|
|
|
|
if [[ $IS_WINDOWS -eq 1 ]]
|
|
then
|
|
PYTHON="python"
|
|
|
|
export CUDA_PATH="$PWD/cuda126"
|
|
export PATH="$PATH:$CUDA_PATH/bin"
|
|
fi
|
|
|
|
if [[ "$@" =~ --first-run ]]
|
|
then
|
|
FIRST_RUN=1
|
|
fi
|
|
|
|
if [[ "$@" =~ --linux-install ]]
|
|
then
|
|
apt install build-essential cmake openjdk-17-jre-headless curl
|
|
|
|
export CUDACXX="/usr/local/cuda-12/bin/nvcc"
|
|
export CMAKE_ARGS="-DGGML_CUDA=on -DCMAKE_CUDA_ARCHITECTURES=native"
|
|
export FORCE_CMAKE="1"
|
|
|
|
pip install llama-cpp-python --no-cache-dir --force-reinstall --upgrade
|
|
|
|
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
|
|
|
|
pip install streamlit
|
|
pip install streamlit_js_eval
|
|
pip install pyqt6 pyqt6-webengine
|
|
|
|
exit 0
|
|
fi
|
|
|
|
if [[ $FIRST_RUN -eq 1 ]]
|
|
then
|
|
pip install streamlit
|
|
pip install streamlit_js_eval
|
|
pip install pyqt6 pyqt6-webengine
|
|
fi
|
|
|
|
|
|
# Used to enter the Python environment for using pip:
|
|
if [[ "$@" =~ --bash ]]
|
|
then
|
|
bash
|
|
exit 0
|
|
fi
|
|
|
|
if [[ "$@" =~ --server ]]
|
|
then
|
|
$PYTHON -u lib/llmhost.py "$@"
|
|
exit 0
|
|
fi
|
|
|
|
if [[ "$@" =~ --streamlit ]]
|
|
then
|
|
streamlit run app.py \
|
|
--server.address $STREAMLIT_HOST \
|
|
--server.port $STREAMLIT_PORT \
|
|
--server.headless true \
|
|
--browser.gatherUsageStats false \
|
|
--server.enableXsrfProtection false \
|
|
--server.enableCORS false \
|
|
--server.enableWebsocketCompression false
|
|
|
|
exit 0
|
|
fi
|
|
|
|
if [[ "$@" =~ --gui ]]
|
|
then
|
|
$PYTHON -u lib/gui.py "$@"
|
|
echo $CHILD_PIDS | xargs kill
|
|
exit 0
|
|
fi
|
|
|
|
|
|
|
|
# You've made it here if you've ran the script without any arguments:
|
|
title "mllm"
|
|
|
|
# https://stackoverflow.com/a/2173421
|
|
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
|
|
|
|
SCRIPT_NAME="$(basename "$0")"
|
|
CHILD_PIDS=""
|
|
|
|
./${SCRIPT_NAME} --server &
|
|
CHILD_PIDS="${CHILD_PIDS} $!"
|
|
|
|
./${SCRIPT_NAME} --streamlit &
|
|
CHILD_PIDS="${CHILD_PIDS} $!"
|
|
|
|
if [[ ! "$@" =~ --headless ]]
|
|
then
|
|
export CHILD_PIDS
|
|
|
|
./${SCRIPT_NAME} --gui &
|
|
CHILD_PIDS="${CHILD_PIDS} $!"
|
|
fi
|
|
|
|
wait ${CHILD_PIDS}
|