Spaces:
Sleeping
Sleeping
Download run.sh from sandy898/resonate-api: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/sandy898/resonate-api/resolve/main/run.sh
- Command line
-
hf download hf://spaces/sandy898/resonate-api/run.sh
-
curl -L -o run.sh https://huggingface.co/spaces/sandy898/resonate-api/resolve/main/run.sh
1.21 kB
| set -e | |
| # Hugging Face Spaces can map persistent storage to a specific directory. | |
| # We will use /app/db_data to store the postgres database to keep it separate | |
| # from the ML data in /app/data. | |
| DB_DIR="/app/db_data/postgres" | |
| # Make sure we have the postgres directory | |
| mkdir -p "$DB_DIR" | |
| export PGDATA="$DB_DIR" | |
| # Ensure the socket directory exists and is accessible | |
| mkdir -p /var/run/postgresql | |
| chmod 775 /var/run/postgresql | |
| # If the database hasn't been initialized yet | |
| if [ -z "$(ls -A $PGDATA)" ]; then | |
| echo "Initializing PostgreSQL database..." | |
| initdb -D $PGDATA | |
| # Start postgres temporarily to create user/db | |
| pg_ctl -D $PGDATA -w start | |
| psql -c "CREATE USER resonate WITH PASSWORD 'resonate_password';" postgres | |
| psql -c "CREATE DATABASE resonate_db OWNER resonate;" postgres | |
| # Stop postgres | |
| pg_ctl -D $PGDATA -w stop | |
| fi | |
| echo "Starting PostgreSQL..." | |
| pg_ctl -D $PGDATA -w start | |
| # Provide the internal localhost URL to the FastAPI app, using port 5432 (default) | |
| export DATABASE_URL="postgresql+asyncpg://resonate:resonate_password@localhost:5432/resonate_db" | |
| echo "Starting FastAPI server..." | |
| exec uvicorn app.main:app --host 0.0.0.0 --port 7860 | |