1+ #! /bin/bash
2+
3+ # Kotaemon UV Installation Script
4+ # This script provides a faster and simpler alternative to conda-based installation
5+
6+ set -euo pipefail
7+
8+ # Colors for output
9+ RED=' \033[0;31m'
10+ GREEN=' \033[0;32m'
11+ YELLOW=' \033[1;33m'
12+ BLUE=' \033[0;34m'
13+ NC=' \033[0m' # No Color
14+
15+ function print_header() {
16+ echo -e " \n${BLUE} ======================================================${NC} "
17+ echo -e " ${BLUE} $1 ${NC} "
18+ echo -e " ${BLUE} ======================================================${NC} \n"
19+ }
20+
21+ function print_success() {
22+ echo -e " ${GREEN} ✓ $1 ${NC} "
23+ }
24+
25+ function print_warning() {
26+ echo -e " ${YELLOW} ⚠ $1 ${NC} "
27+ }
28+
29+ function print_error() {
30+ echo -e " ${RED} ✗ $1 ${NC} "
31+ }
32+
33+ function check_path_for_spaces() {
34+ if [[ $PWD =~ \ ]]; then
35+ print_error " The current workdir has whitespace which can lead to unintended behaviour. Please modify your path and continue later."
36+ exit 1
37+ fi
38+ }
39+
40+ function check_python_version() {
41+ print_success " uv will automatically manage Python 3.10 - no manual Python installation needed!"
42+ }
43+
44+ function install_uv() {
45+ if command -v uv & > /dev/null; then
46+ print_success " uv is already installed"
47+ return 0
48+ fi
49+
50+ print_header " Installing uv package manager"
51+
52+ if command -v curl & > /dev/null; then
53+ curl -LsSf https://astral.sh/uv/install.sh | sh
54+ elif command -v wget & > /dev/null; then
55+ wget -qO- https://astral.sh/uv/install.sh | sh
56+ else
57+ print_error " Neither curl nor wget is available. Please install one of them."
58+ exit 1
59+ fi
60+
61+ # Add uv to PATH for current session
62+ export PATH=" $HOME /.local/bin:$PATH "
63+
64+ if command -v uv & > /dev/null; then
65+ print_success " uv installed successfully"
66+ else
67+ print_error " uv installation failed"
68+ exit 1
69+ fi
70+ }
71+
72+ function setup_environment() {
73+ print_header " Setting up Python environment with uv"
74+
75+ # Create virtual environment with Python 3.10 (uv will download Python if needed)
76+ if [[ ! -d " .venv" ]]; then
77+ print_success " Creating virtual environment with Python 3.10 (uv will download if needed)..."
78+ uv venv --python 3.10
79+ print_success " Created virtual environment"
80+ else
81+ print_warning " Virtual environment already exists"
82+ fi
83+
84+ # Activate virtual environment
85+ source .venv/bin/activate
86+ print_success " Activated virtual environment"
87+ }
88+
89+ function install_dependencies() {
90+ print_header " Installing dependencies"
91+
92+ # Use the exact same approach as conda scripts for compatibility
93+ print_success " Installing kotaemon with exact dependency resolution..."
94+
95+ # Install in the exact same order as the original conda script
96+ uv pip install -e " libs/kotaemon[all]"
97+ uv pip install -e " libs/ktem"
98+
99+ # Fix known version conflicts mentioned in the README
100+ print_success " Resolving known version conflicts..."
101+ uv pip uninstall hnswlib chroma-hnswlib -y 2> /dev/null || true
102+ uv pip install chroma-hnswlib
103+
104+ print_success " Dependencies installed successfully"
105+ }
106+
107+ function setup_pdfjs() {
108+ print_header " Setting up PDF.js viewer"
109+
110+ local pdfjs_dir=" libs/ktem/ktem/assets/prebuilt/pdfjs-4.0.379-dist"
111+
112+ if [[ -d " $pdfjs_dir " ]]; then
113+ print_warning " PDF.js already exists, skipping download"
114+ return 0
115+ fi
116+
117+ if [[ -f " scripts/download_pdfjs.sh" ]]; then
118+ bash scripts/download_pdfjs.sh " $pdfjs_dir "
119+ print_success " PDF.js setup completed"
120+ else
121+ print_warning " PDF.js download script not found. You may need to set this up manually."
122+ fi
123+ }
124+
125+ function setup_env_file() {
126+ print_header " Setting up environment configuration"
127+
128+ if [[ ! -f " .env" && -f " .env.example" ]]; then
129+ cp .env.example .env
130+ print_success " Created .env file from template"
131+ print_warning " Please edit .env file to configure your API keys"
132+ elif [[ -f " .env" ]]; then
133+ print_warning " .env file already exists"
134+ else
135+ print_warning " No .env.example found. You may need to configure environment variables manually."
136+ fi
137+ }
138+
139+ function launch_app() {
140+ print_header " Launching Kotaemon"
141+
142+ print_success " Starting the application..."
143+ print_warning " The app will be automatically launched in your browser"
144+ print_warning " Default username and password are both 'admin'"
145+
146+ # Set PDF.js environment variable if directory exists
147+ local pdfjs_dir=" libs/ktem/ktem/assets/prebuilt/pdfjs-4.0.379-dist"
148+ if [[ -d " $pdfjs_dir " ]]; then
149+ export PDFJS_PREBUILT_DIR=" $pdfjs_dir "
150+ fi
151+
152+ python app.py
153+ }
154+
155+ function main() {
156+ print_header " Kotaemon UV-based Installation"
157+
158+ # Move to project root
159+ cd " $( dirname " ${BASH_SOURCE[0]} " ) " && cd ..
160+
161+ check_path_for_spaces
162+ check_python_version
163+ install_uv
164+ setup_environment
165+ install_dependencies
166+ setup_pdfjs
167+ setup_env_file
168+
169+ print_success " Installation completed successfully!"
170+ echo
171+ print_warning " To launch the application in the future, run:"
172+ echo -e " ${BLUE} cd $( pwd) ${NC} "
173+ echo -e " ${BLUE} source .venv/bin/activate${NC} "
174+ echo -e " ${BLUE} python app.py${NC} "
175+ echo
176+
177+ read -p " Do you want to launch the application now? [Y/n] " -n 1 -r
178+ echo
179+ if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
180+ launch_app
181+ else
182+ print_success " You can launch the application later using the commands above."
183+ fi
184+ }
185+
186+ # Run main function
187+ main " $@ "
0 commit comments