Spaces:
Runtime error

File size: 1,578 Bytes
b06c2b5
 
 
d453a61
 
 
 
b06c2b5
 
d453a61
 
 
 
 
f419df4
 
 
 
eae9e17
f419df4
 
b06c2b5
 
 
 
f419df4
b06c2b5
93117c2
 
 
 
 
 
 
 
9960f53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/sh
set -e

# Guard — fail fast with a clear message if DATABASE_URL is missing
if [ -z "$DATABASE_URL" ]; then
  echo "ERROR: DATABASE_URL is not set. Add it in HuggingFace Space Settings → Secrets."
  exit 1
fi

# Supabase / Neon provide postgres:// — SQLAlchemy asyncpg needs postgresql+asyncpg://
export DATABASE_URL=$(echo "$DATABASE_URL" \
  | sed 's|^postgres://|postgresql+asyncpg://|' \
  | sed 's|^postgresql://|postgresql+asyncpg://|')

# HuggingFace persistent volume — ChromaDB lives here across restarts
mkdir -p /data/chroma_db
export CHROMA_PERSIST_DIR=${CHROMA_PERSIST_DIR:-/data/chroma_db}

# Both processes share this container — worker calls /api/kb/search on localhost
export BACKEND_INTERNAL_URL=${BACKEND_INTERNAL_URL:-http://localhost:7860}

echo "▶ Running database migrations..."
alembic upgrade head

echo "▶ Seeding demo data..."
python seed.py || echo "   Seed skipped (already up to date)"

echo "▶ Starting Wavvy API..."
uvicorn main:app --host 0.0.0.0 --port 7860 --workers 2 &
API_PID=$!

echo "▶ Starting LiveKit Worker..."
python -m voice.agent_worker start &
WORKER_PID=$!

# If either process exits, kill the other and propagate the exit code.
# wait -n is bash-only; poll manually for POSIX sh (HuggingFace uses dash).
while true; do
  if ! kill -0 $API_PID 2>/dev/null; then
    wait $API_PID; EXIT_CODE=$?
    kill $WORKER_PID 2>/dev/null
    exit $EXIT_CODE
  fi
  if ! kill -0 $WORKER_PID 2>/dev/null; then
    wait $WORKER_PID; EXIT_CODE=$?
    kill $API_PID 2>/dev/null
    exit $EXIT_CODE
  fi
  sleep 2
done