hfstudio / run_dev.sh
GitHub Action
Sync from GitHub: 36529f229356b9c3c1e998307c423d9b56d07437
20ad004
#!/bin/bash
# Script to run both frontend and backend in development mode
echo "πŸš€ Starting HFStudio Development Environment..."
echo ""
# Kill any processes running on the required ports
echo "Checking for processes on ports 7860 and 11111..."
if lsof -Pi :7860 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
echo "Killing process on port 7860..."
lsof -Pi :7860 -sTCP:LISTEN -t | xargs kill -9 2>/dev/null
fi
if lsof -Pi :11111 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
echo "Killing process on port 11111..."
lsof -Pi :11111 -sTCP:LISTEN -t | xargs kill -9 2>/dev/null
fi
echo ""
# Check if tmux is installed
if command -v tmux &> /dev/null; then
# Create a new tmux session
tmux new-session -d -s hfstudio
# Split window horizontally
tmux split-window -h
# Run backend in left pane
tmux send-keys -t hfstudio:0.0 'python -m hfstudio.cli dev-server --dev' C-m
# Run frontend in right pane
tmux send-keys -t hfstudio:0.1 'cd frontend && npm install && npm run dev' C-m
# Attach to session
tmux attach-session -t hfstudio
else
# Run without tmux
echo "Running without tmux (install tmux for better experience)"
echo ""
echo "Starting Backend..."
python -m hfstudio.cli dev-server --dev &
BACKEND_PID=$!
echo "Starting Frontend..."
cd frontend
npm install
npm run dev &
FRONTEND_PID=$!
echo ""
echo "Services running:"
echo " Frontend: http://localhost:11111"
echo " Backend: http://localhost:7860"
echo " API Docs: http://localhost:7860/docs"
echo ""
# Wait for frontend to be ready then open browser
echo "Waiting for services to start..."
sleep 3
# Open browser based on OS
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
open http://localhost:11111
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
xdg-open http://localhost:11111 2>/dev/null || sensible-browser http://localhost:11111
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
# Windows
start http://localhost:11111
fi
echo "Browser opened at http://localhost:11111"
echo ""
echo "Press Ctrl+C to stop all services"
# Wait and handle shutdown
trap "kill $BACKEND_PID $FRONTEND_PID" EXIT
wait
fi