secondme-api / start.sh
harvesthealth's picture
Upload folder using huggingface_hub
dd78bf5 verified
#!/bin/bash
set -e
echo "--- Starting application... ---"
# Use relative paths for scripts
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Ensure we are in the app directory
cd "$SCRIPT_DIR"
# Initialize database if needed
echo "--- Checking SQLite database... ---"
if [ ! -s ./data/sqlite/lpm.db ]; then
echo "SQLite database not found or empty, initializing..."
mkdir -p ./data/sqlite
sqlite3 ./data/sqlite/lpm.db < ./docker/sqlite/init.sql
echo "SQLite database initialized successfully"
else
echo "SQLite database already exists"
fi
# Initialize ChromaDB if needed
echo "--- Checking ChromaDB... ---"
if [ ! -d ./data/chroma_db/documents ] || [ ! -d ./data/chroma_db/document_chunks ]; then
echo "ChromaDB collections not found, initializing..."
python ./docker/app/init_chroma.py
echo "ChromaDB initialized successfully"
else
echo "ChromaDB already exists"
fi
# Try to run setup if it exists and hasn't been run
if [ -f "./scripts/setup.sh" ]; then
echo "Checking if setup is needed..."
# We skip full setup in container but could do minor checks
fi
echo "Starting Flask application..."
export FLASK_APP=lpm_kernel.app
export PYTHONPATH=$PYTHONPATH:.
# Use port 7860 for Hugging Face Spaces by default if LOCAL_APP_PORT is not set
PORT=${LOCAL_APP_PORT:-7860}
echo "Running on port $PORT"
python -m flask run --host=0.0.0.0 --port=$PORT