-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·190 lines (167 loc) · 6.79 KB
/
install.sh
File metadata and controls
executable file
·190 lines (167 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash
# Default values
PYTHON_VERSION="python3"
USE_CUDA=false
# Parse command line arguments
while getopts "p:c" opt; do
case $opt in
p) PYTHON_VERSION="$OPTARG"
;;
c) USE_CUDA=true
;;
*) echo "Usage: $0 [-p python_version] [-c]"
echo " -p: Specify Python version (default: python3)"
echo " -c: Install with CUDA support (default: CPU only)"
exit 1
;;
esac
done
echo "Using Python version: $PYTHON_VERSION"
if [ "$USE_CUDA" = true ]; then
echo "Installing with CUDA support"
else
echo "Installing with CPU-only PyTorch"
fi
# Check if uv is installed, install if not
if ! command -v uv &> /dev/null; then
echo "uv could not be found. Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add uv to PATH for current session
export PATH="$HOME/.local/bin:$PATH"
# Verify installation
if ! command -v uv &> /dev/null; then
echo "ERROR: Failed to install uv. Please install uv manually and try again."
echo "Visit https://docs.astral.sh/uv/getting-started/installation/ for installation instructions."
exit 1
else
echo "uv installed successfully"
fi
else
echo "uv is already installed"
fi
# Delete virtual environment if it already exists
if [ -d /var/lib/text-pair/textpair_env ]; then
echo "Deleting existing TextPAIR installation..."
sudo rm -rf /var/lib/text-pair/textpair_env
fi
# Give current user permission to write to /var/lib/textpair
sudo mkdir -p /var/lib/text-pair
sudo chown -R $USER:$(id -gn) /var/lib/text-pair
# Create the virtual environment using uv
echo "Creating virtual environment with uv..."
uv venv -p $PYTHON_VERSION /var/lib/text-pair/textpair_env
source /var/lib/text-pair/textpair_env/bin/activate
# Install textpair and textpair_llm together
if [ "$USE_CUDA" = true ]; then
echo "Installing textpair with CUDA support..."
uv pip install -e lib/.[cuda]
else
echo "Installing textpair with CPU-only PyTorch..."
uv pip install -e lib/.[cpu]
fi
deactivate
# Create separate virtual environment for graph building
echo ""
echo "Creating separate virtual environment for graph building..."
if [ -d /var/lib/text-pair/graph ]; then
echo "Deleting existing graph environment..."
rm -rf /var/lib/text-pair/graph
fi
uv venv -p $PYTHON_VERSION /var/lib/text-pair/graph
source /var/lib/text-pair/graph/bin/activate
# Install textpair_graph and textpair_llm together
echo "Installing textpair_graph..."
if [ "$USE_CUDA" = true ]; then
echo "Installing with GPU acceleration (cuML)..."
uv pip install -e lib/textpair_graph[cuda] || {
echo "WARNING: Failed to install CUDA graph libraries. Falling back to CPU alternatives..."
uv pip install -e lib/textpair_graph
}
else
echo "Installing CPU-only graph dependencies..."
uv pip install -e lib/textpair_graph
fi
deactivate
echo "Graph building environment created at /var/lib/text-pair/graph"
# Install the textpair script
sudo cp textpair /usr/local/bin/
# Install compareNgrams binary
arch=$(uname -m)
if [ "$arch" = "x86_64" ]; then
binary_path="lib/core/binary/x86_64/compareNgrams"
elif [ "$arch" = "aarch64" ] || [ "$arch" = "arm64" ]; then
binary_path="lib/core/binary/aarch64/compareNgrams"
else
echo "Only x86_64 and ARM are supported at this time."
exit 1
fi
sudo rm -f /usr/local/bin/compareNgrams
sudo cp "$binary_path" /usr/local/bin/compareNgrams
sudo chmod +x /usr/local/bin/compareNgrams
# Install the web application components
echo -e "\nMoving web application components into place..."
sudo mkdir -p /var/lib/text-pair
if [ ! -f /var/lib/text-pair/api_server/web_server.sh ]
then
sudo cp -Rf api_server /var/lib/text-pair/api_server/
else
echo "/var/lib/text-pair/api_server/web_server.sh already exists, not modifying..."
fi
if [ -d web/web_app/node_modules ]
then
sudo rm -rf web/web_app/node_modules
fi
sudo cp -Rf api /var/lib/text-pair/
sudo cp -Rf web-app /var/lib/text-pair/
sudo cp -Rf config /var/lib/text-pair/
echo -e "\nMoving global configuration into place..."
sudo mkdir -p /etc/text-pair
if [ ! -f /etc/text-pair/global_settings.ini ]
then
sudo touch /etc/text-pair/global_settings.ini
echo "[WEB_APP]" | sudo tee -a /etc/text-pair/global_settings.ini > /dev/null
echo "api_server = http://localhost/text-pair-api" | sudo tee -a /etc/text-pair/global_settings.ini > /dev/null
echo "web_app_path =" | sudo tee -a /etc/text-pair/global_settings.ini > /dev/null
echo "[DATABASE]" | sudo tee -a /etc/text-pair/global_settings.ini > /dev/null
echo "database_name =" | sudo tee -a /etc/text-pair/global_settings.ini > /dev/null
echo "database_user =" | sudo tee -a /etc/text-pair/global_settings.ini > /dev/null
echo "database_password =" | sudo tee -a /etc/text-pair/global_settings.ini > /dev/null
echo "Make sure you create a PostgreSQL database with a user with read/write access to that database and configure /etc/text-pair/global_settings.ini accordingly."
else
echo "/etc/text-pair/global_settings.ini already exists, not modifying..."
fi
# Check if pgvector extension is available in PostgreSQL
echo ""
echo "Checking for pgvector extension in PostgreSQL..."
if [ -f /usr/share/postgresql/*/extension/vector.control ] || [ -f /usr/local/share/postgresql/*/extension/vector.control ]; then
echo "✓ pgvector extension found in PostgreSQL"
echo ""
echo "IMPORTANT: Before using TextPAIR, you must enable the vector extension in your database."
echo "As a PostgreSQL superuser, run:"
echo " psql -d your_textpair_database -c 'CREATE EXTENSION IF NOT EXISTS vector;'"
else
echo ""
echo "ERROR: pgvector extension not found!"
echo "TextPAIR requires the pgvector extension for PostgreSQL."
echo ""
echo "To install pgvector:"
echo " See https://github.com/pgvector/pgvector?tab=readme-ov-file#installation for installation instructions."
echo ""
echo "After installing pgvector, run this install script again."
echo ""
exit 1
fi
echo -e "\n## INSTALLATION COMPLETE ##"
echo "TextPAIR has been installed successfully using uv!"
if [ "$USE_CUDA" = true ]; then
echo "- PyTorch was installed with CUDA support"
else
echo "- PyTorch was installed with CPU-only support"
echo "- To install with CUDA support in the future, run: $0 -c"
fi
echo ""
echo "## NEXT STEPS ##"
echo "In order to start the TextPAIR web app, you need to configure and start up the web_server.sh script."
echo "You can either:"
echo "- Start it manually at /var/lib/text-pair/api_server/web_server.sh"
echo "- Use the systemd init script located at /var/lib/text-pair/api_server/textpair.service: for this you will need to copy it to your OS systemd folder (usually /etc/systemd/system/) and run 'systemctl enable textpair && systemctl start textpair' as root"