2026-02-27 18:47:03 +09:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Kotaemon UV Installation Script
|
|
|
|
|
# This script provides a faster and simpler alternative to conda-based installation
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
# Colors for output
|
|
|
|
|
RED='\033[0;31m'
|
2026-05-31 12:18:12 +07:00
|
|
|
GREEN='\033[0;32m'
|
2026-02-27 18:47:03 +09:00
|
|
|
YELLOW='\033[1;33m'
|
|
|
|
|
BLUE='\033[0;34m'
|
|
|
|
|
NC='\033[0m' # No Color
|
|
|
|
|
|
|
|
|
|
function print_header() {
|
|
|
|
|
echo -e "\n${BLUE}======================================================${NC}"
|
|
|
|
|
echo -e "${BLUE}$1${NC}"
|
|
|
|
|
echo -e "${BLUE}======================================================${NC}\n"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function print_success() {
|
|
|
|
|
echo -e "${GREEN}✓ $1${NC}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function print_warning() {
|
|
|
|
|
echo -e "${YELLOW}⚠ $1${NC}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function print_error() {
|
|
|
|
|
echo -e "${RED}✗ $1${NC}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function check_path_for_spaces() {
|
|
|
|
|
if [[ $PWD =~ \ ]]; then
|
|
|
|
|
print_error "The current workdir has whitespace which can lead to unintended behaviour. Please modify your path and continue later."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function check_python_version() {
|
|
|
|
|
print_success "uv will automatically manage Python 3.10 - no manual Python installation needed!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function install_uv() {
|
|
|
|
|
if command -v uv &> /dev/null; then
|
|
|
|
|
print_success "uv is already installed"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
print_header "Installing uv package manager"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
if command -v curl &> /dev/null; then
|
|
|
|
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
|
|
|
elif command -v wget &> /dev/null; then
|
|
|
|
|
wget -qO- https://astral.sh/uv/install.sh | sh
|
|
|
|
|
else
|
|
|
|
|
print_error "Neither curl nor wget is available. Please install one of them."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
# Add uv to PATH for current session
|
|
|
|
|
export PATH="$HOME/.local/bin:$PATH"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
if command -v uv &> /dev/null; then
|
|
|
|
|
print_success "uv installed successfully"
|
|
|
|
|
else
|
|
|
|
|
print_error "uv installation failed"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setup_environment() {
|
|
|
|
|
print_header "Setting up Python environment with uv"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
# Create virtual environment with Python 3.10 (uv will download Python if needed)
|
|
|
|
|
if [[ ! -d ".venv" ]]; then
|
|
|
|
|
print_success "Creating virtual environment with Python 3.10 (uv will download if needed)..."
|
|
|
|
|
uv venv --python 3.10
|
|
|
|
|
print_success "Created virtual environment"
|
|
|
|
|
else
|
|
|
|
|
print_warning "Virtual environment already exists"
|
|
|
|
|
fi
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
# Activate virtual environment
|
|
|
|
|
source .venv/bin/activate
|
|
|
|
|
print_success "Activated virtual environment"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function install_dependencies() {
|
|
|
|
|
print_header "Installing dependencies"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
# Use the exact same approach as conda scripts for compatibility
|
|
|
|
|
print_success "Installing kotaemon with exact dependency resolution..."
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
# Install in the exact same order as the original conda script
|
|
|
|
|
uv pip install -e "libs/kotaemon[all]"
|
|
|
|
|
uv pip install -e "libs/ktem"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
# Fix known version conflicts mentioned in the README
|
|
|
|
|
print_success "Resolving known version conflicts..."
|
|
|
|
|
uv pip uninstall hnswlib chroma-hnswlib -y 2>/dev/null || true
|
|
|
|
|
uv pip install chroma-hnswlib
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
print_success "Dependencies installed successfully"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setup_pdfjs() {
|
|
|
|
|
print_header "Setting up PDF.js viewer"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
local pdfjs_dir="libs/ktem/ktem/assets/prebuilt/pdfjs-4.0.379-dist"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
if [[ -d "$pdfjs_dir" ]]; then
|
|
|
|
|
print_warning "PDF.js already exists, skipping download"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
if [[ -f "scripts/download_pdfjs.sh" ]]; then
|
|
|
|
|
bash scripts/download_pdfjs.sh "$pdfjs_dir"
|
|
|
|
|
print_success "PDF.js setup completed"
|
|
|
|
|
else
|
|
|
|
|
print_warning "PDF.js download script not found. You may need to set this up manually."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setup_env_file() {
|
|
|
|
|
print_header "Setting up environment configuration"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
if [[ ! -f ".env" && -f ".env.example" ]]; then
|
|
|
|
|
cp .env.example .env
|
|
|
|
|
print_success "Created .env file from template"
|
|
|
|
|
print_warning "Please edit .env file to configure your API keys"
|
|
|
|
|
elif [[ -f ".env" ]]; then
|
|
|
|
|
print_warning ".env file already exists"
|
|
|
|
|
else
|
|
|
|
|
print_warning "No .env.example found. You may need to configure environment variables manually."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function launch_app() {
|
|
|
|
|
print_header "Launching Kotaemon"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
print_success "Starting the application..."
|
|
|
|
|
print_warning "The app will be automatically launched in your browser"
|
|
|
|
|
print_warning "Default username and password are both 'admin'"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
# Set PDF.js environment variable if directory exists
|
|
|
|
|
local pdfjs_dir="libs/ktem/ktem/assets/prebuilt/pdfjs-4.0.379-dist"
|
|
|
|
|
if [[ -d "$pdfjs_dir" ]]; then
|
|
|
|
|
export PDFJS_PREBUILT_DIR="$pdfjs_dir"
|
|
|
|
|
fi
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
python app.py
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
|
print_header "Kotaemon UV-based Installation"
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
# Move to project root
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")" && cd ..
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
check_path_for_spaces
|
|
|
|
|
check_python_version
|
|
|
|
|
install_uv
|
|
|
|
|
setup_environment
|
|
|
|
|
install_dependencies
|
|
|
|
|
setup_pdfjs
|
|
|
|
|
setup_env_file
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
print_success "Installation completed successfully!"
|
|
|
|
|
echo
|
|
|
|
|
print_warning "To launch the application in the future, run:"
|
|
|
|
|
echo -e " ${BLUE}cd $(pwd)${NC}"
|
|
|
|
|
echo -e " ${BLUE}source .venv/bin/activate${NC}"
|
|
|
|
|
echo -e " ${BLUE}python app.py${NC}"
|
|
|
|
|
echo
|
2026-05-31 12:18:12 +07:00
|
|
|
|
2026-02-27 18:47:03 +09:00
|
|
|
read -p "Do you want to launch the application now? [Y/n] " -n 1 -r
|
|
|
|
|
echo
|
|
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
|
|
|
|
|
launch_app
|
|
|
|
|
else
|
|
|
|
|
print_success "You can launch the application later using the commands above."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Run main function
|
2026-05-31 12:18:12 +07:00
|
|
|
main "$@"
|