File size: 2,081 Bytes
3eaaf3a
 
a8e6d06
 
 
 
 
 
 
 
 
 
 
 
 
3eaaf3a
 
 
 
 
186d7c9
3eaaf3a
 
186d7c9
3eaaf3a
 
e510c4e
5144b92
186d7c9
 
 
e88cde7
e510c4e
a8e6d06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3eaaf3a
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
#!/bin/bash

# Set up cache directories
export HF_HUB_CACHE=/tmp/huggingface
export TRANSFORMERS_CACHE=/tmp/transformers
export TORCH_HOME=/tmp/torch

# Clean up old cache files
echo "Cleaning up cache directories..."
rm -rf /tmp/huggingface/* /tmp/transformers/* /tmp/torch/* 2>/dev/null || true

# Clean up system temp files
echo "Cleaning up system temporary files..."
rm -rf /tmp/*.log /tmp/*.tmp /tmp/*.cache 2>/dev/null || true

if [ ! -d "llama.cpp" ]; then
  # only run in dev env
  git clone https://github.com/ggerganov/llama.cpp
fi

export GGML_CUDA=OFF
if [[ -z "${RUN_LOCALLY}" ]]; then
  # enable CUDA if NOT running locally
  export GGML_CUDA=ON
fi

cd llama.cpp
cmake -B build -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=${GGML_CUDA}
cmake --build build --config Release -j --target llama-quantize llama-gguf-split llama-imatrix
cp ./build/bin/llama-* .
rm -rf build

cd ..

# Comprehensive cleanup before starting
echo "Performing comprehensive cleanup..."
# Clean Python cache files
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
find . -type f -name "*.pyd" -delete
find . -type d -name "__pycache__" -exec rm -r {} + 2>/dev/null || true
find . -type d -name ".pytest_cache" -exec rm -r {} + 2>/dev/null || true
find . -type d -name ".coverage" -exec rm -r {} + 2>/dev/null || true

# Clean temporary files
find . -type f -name "*.tmp" -delete
find . -type f -name "*.temp" -delete
find . -type f -name "*.log" -delete
find . -type f -name "*.cache" -delete

# Clean build artifacts
find . -type d -name "build" -exec rm -r {} + 2>/dev/null || true
find . -type d -name "dist" -exec rm -r {} + 2>/dev/null || true
find . -type d -name "*.egg-info" -exec rm -r {} + 2>/dev/null || true

# Clean downloads directory if it exists
if [ -d "downloads" ]; then
    echo "Cleaning downloads directory..."
    find downloads -type f -mtime +1 -delete 2>/dev/null || true
fi

# Clean up any remaining temporary files in the current directory
rm -f *.log *.tmp *.temp 2>/dev/null || true

echo "Cleanup completed. Starting application..."
python app.py