Spaces:
Sleeping
Sleeping
File size: 4,848 Bytes
45b6536 |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
#!/bin/bash
# V4 Local Testing Server Startup Script
# This script starts the FastAPI server with V4 enabled for Android app testing
set -e
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${BLUE}β V4 Local Testing Server β${NC}"
echo -e "${BLUE}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
# Check if server is already running
if lsof -Pi :7860 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo -e "${YELLOW}β οΈ Server already running on port 7860${NC}"
echo -e "${YELLOW} Stopping existing server...${NC}"
pkill -f "uvicorn app.main:app" || true
sleep 2
fi
# Get local IP address
LOCAL_IP=$(ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}' | head -1)
if [ -z "$LOCAL_IP" ]; then
LOCAL_IP="Unable to detect"
echo -e "${RED}β οΈ Could not detect local IP address${NC}"
else
echo -e "${GREEN}β
Local IP Address: ${LOCAL_IP}${NC}"
fi
# Check .env configuration
if [ -f ".env" ]; then
echo -e "${GREEN}β
Found .env configuration${NC}"
# Show V4 config
echo ""
echo -e "${BLUE}V4 Configuration:${NC}"
grep "^ENABLE_V4" .env || echo " No V4 settings found"
grep "^V4_MODEL_ID" .env || echo " No model configured"
grep "^V4_MAX_TOKENS" .env || echo " Using default tokens"
else
echo -e "${RED}β No .env file found!${NC}"
echo -e "${YELLOW} Please create .env with V4 configuration${NC}"
exit 1
fi
echo ""
echo -e "${BLUE}Starting server...${NC}"
echo -e "${BLUE}This may take 30-90 seconds for V4 model warmup${NC}"
echo ""
# Start server in background and log to file
/opt/anaconda3/envs/summarizer/bin/python -m uvicorn app.main:app \
--host 0.0.0.0 \
--port 7860 \
> server.log 2>&1 &
SERVER_PID=$!
echo -e "${GREEN}β
Server started (PID: ${SERVER_PID})${NC}"
# Wait for server to be ready
echo -e "${YELLOW}β³ Waiting for server to initialize...${NC}"
TIMEOUT=120
ELAPSED=0
while [ $ELAPSED -lt $TIMEOUT ]; do
if lsof -Pi :7860 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo -e "${GREEN}β
Server is listening on port 7860${NC}"
break
fi
sleep 2
ELAPSED=$((ELAPSED + 2))
# Show progress every 10 seconds
if [ $((ELAPSED % 10)) -eq 0 ]; then
echo -e "${YELLOW} Still loading... (${ELAPSED}s / ${TIMEOUT}s)${NC}"
fi
done
if [ $ELAPSED -ge $TIMEOUT ]; then
echo -e "${RED}β Server failed to start within ${TIMEOUT} seconds${NC}"
echo -e "${YELLOW} Check server.log for errors${NC}"
exit 1
fi
# Wait a bit more for V4 warmup
echo -e "${YELLOW}β³ Waiting for V4 model warmup (may take 60-90s)...${NC}"
sleep 15
# Test health endpoint
echo ""
echo -e "${BLUE}Testing server health...${NC}"
if curl -s http://localhost:7860/health > /dev/null 2>&1; then
echo -e "${GREEN}β
Server is healthy and responding${NC}"
else
echo -e "${YELLOW}β οΈ Health check failed, but server may still be warming up${NC}"
fi
echo ""
echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${GREEN}β Server Started Successfully! β${NC}"
echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
echo -e "${BLUE}Local Access:${NC}"
echo -e " http://localhost:7860"
echo ""
echo -e "${BLUE}Android App URL:${NC}"
echo -e " http://${LOCAL_IP}:7860"
echo ""
echo -e "${BLUE}V4 NDJSON Endpoint:${NC}"
echo -e " POST http://${LOCAL_IP}:7860/api/v4/scrape-and-summarize/stream-ndjson"
echo ""
echo -e "${BLUE}API Documentation:${NC}"
echo -e " http://localhost:7860/docs"
echo ""
echo -e "${BLUE}Server Logs:${NC}"
echo -e " tail -f server.log"
echo ""
echo -e "${BLUE}Stop Server:${NC}"
echo -e " pkill -f 'uvicorn app.main:app'"
echo -e " or: kill ${SERVER_PID}"
echo ""
echo -e "${YELLOW}π± Update your Android app base URL to: http://${LOCAL_IP}:7860${NC}"
echo -e "${YELLOW}π See ANDROID_V4_LOCAL_TESTING.md for complete setup guide${NC}"
echo ""
# Optionally tail logs
read -p "Show real-time logs? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${BLUE}Showing server logs (Ctrl+C to stop)...${NC}"
tail -f server.log
fi
|