-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·208 lines (174 loc) · 5.16 KB
/
run.sh
File metadata and controls
executable file
·208 lines (174 loc) · 5.16 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# !/bin/sh
PID_FILE="app_pid.txt"
LOG_DIRECTORY="logs"
OSTYPE=$(uname -s)
set -e
# this will create venv from python version defined in .python-version
if [ ! -d .venv ]; then
uv venv
fi
# Activate the virtual environment using the dot command
. .venv/bin/activate
# install requirements for the project
uv pip install --upgrade -r requirements.txt --quiet
log_message() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# Function to check the operating system
check_os() {
echo $OSTYPE
case "$OSTYPE" in
Darwin*)
log_message "✅ macOS detected. Proceeding with installation..."
OS="macos"
;;
Linux*)
log_message "✅ Linux detected. Proceeding with installation..."
OS="linux"
;;
*)
log_message "❌ Unsupported operating system: $OSTYPE"
exit 1
;;
esac
}
# Function to check if Ollama is already installed
check_ollama_installed() {
if command -v ollama &>/dev/null; then
echo 1
else
echo 0
fi
}
# Function to check if Homebrew is installed (for macOS)
check_homebrew() {
if ! command -v brew &>/dev/null; then
log_message "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
log_message "✅ Homebrew is already installed."
fi
}
# Function to install Ollama on macOS
install_ollama_macos() {
log_message "🚀 Installing Ollama on macOS..."
brew update
brew install ollama
}
# Function to install Ollama on Linux
install_ollama_linux() {
log_message "🚀 Installing Ollama on Linux..."
# Download and install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
}
# Function to check if Ollama is installed
check_ollama() {
if command -v ollama &>/dev/null; then
log_message "✅ Ollama is installed. Version:"
else
log_message "❌ Failed to install Ollama. Please check your system configuration."
exit 1
fi
}
is_ollama_running() {
if command -v netstat >/dev/null; then
if netstat -tuln 2>/dev/null | grep -q ":11434 "; then
return 0
fi
fi
return 1
}
# Main installation steps
log_message "Starting Ollama installation..."
# Step 1: Check the operating system
check_os
# Step 2: Perform installation based on OS
installed_flag=$(check_ollama_installed);
if [[ "$OS" == "macos" && $installed_flag -eq 0 ]]; then
check_homebrew
install_ollama_macos
elif [[ "$OS" == "linux" && $installed_flag -eq 0 ]]; then
install_ollama_linux
else
log_message "✅ Ollama is already installed. Version:"
ollama --version
fi
# Step 3: Check Ollama service status
log_message "Checking Ollama service status..."
if is_ollama_running; then
log_message "Ollama is already running"
else
log_message "Ollama is not running. Starting Ollama..."
if command -v ollama >/dev/null; then
nohup ollama serve > logs/ollama_serve.log 2>&1 &
sleep 2 # Give it a moment to start
if check_ollama; then
log_message "✅ Ollama started successfully"
else
log_message "❌ Error: Failed to start Ollama"
exit 1
fi
else
log_message "❌ Error: Ollama is not installed"
exit 1
fi
fi
log_message "🎉 Ollama installation complete!"
# install ollama models (suggested options)
# ollama pull qwen2:1.5b
# ollama pull qwen2.5:1.5b # best larger model
# ollama pull qwen2.5:0.5b # default model
# ollama pull smollm2:135m
# ollama pull smollm2:360m
# ollama pull tinyllama
# ollama pull tinydolphin
# ollama pull granite3-moe
ollama run deepseek-r1:1.5b #officialy best possible model
# Output Python version
log_message "Running fed_rag with $(python3 --version) at '$(which python3)'"
is_gradio_running() {
if [ -f "$PID_FILE" ]; then
pid=$(cat "$PID_FILE")
if ps -p "$pid" > /dev/null; then
if curl -s http://localhost:7861 > /dev/null; then
return 0
fi
fi
fi
# Also check if port is in use by any process
if lsof -i:7861 > /dev/null 2>&1; then
return 1
fi
return 1
}
start_gradio() {
log_message "Starting Gradio application..."
setsid python app.py > "logs/app.log" 2>&1 &
APP_PID=$!
echo "$APP_PID" > "$PID_FILE"
for i in {1..100}; do
sleep 10
if curl -s http://localhost:7861 > /dev/null; then
log_message "✅ Gradio app started successfully! (PID: $APP_PID) Go to: http://localhost:7861"
return 0
fi
done
log_message "❌ Failed to start Gradio app. Check logs at $APP_LOG"
rm -f "$PID_FILE"
return 1
}
if is_gradio_running; then
log_message "Gradio app is already running"
if [ -f "$PID_FILE" ]; then
log_message "PID: $(cat "$PID_FILE")"
else
log_message "PID file not found, but port 7861 is in use"
fi
else
rm -f "$PID_FILE"
start_gradio
fi
# Run the index updater every 5 mins
python3 index_updater.py > "logs/index_updater.log" 2>&1 &
# deactivate the virtual environment
deactivate