#!/bin/bash # ========================================= # πŸ“Š Update HuggingFace with Monitoring # ========================================= # Script to update HF Spaces with monitoring # ========================================= set -e # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' echo -e "${GREEN}================================================${NC}" echo -e "${GREEN}πŸ“Š Updating HuggingFace Spaces with Monitoring${NC}" echo -e "${GREEN}================================================${NC}" # Check if we're in the right directory if [ ! -f "app.py" ]; then echo -e "${RED}❌ Error: app.py not found. Run from project root.${NC}" exit 1 fi # Check current branch CURRENT_BRANCH=$(git branch --show-current) echo -e "${YELLOW}πŸ“ Current branch: $CURRENT_BRANCH${NC}" # Stash any local changes echo -e "${YELLOW}πŸ’Ύ Stashing local changes...${NC}" git stash # Stay on main branch echo -e "${YELLOW}πŸ“ Staying on main branch...${NC}" # Pull latest changes echo -e "${YELLOW}πŸ“₯ Pulling latest changes...${NC}" git pull origin main # Apply the monitoring updates echo -e "${YELLOW}πŸ“ Applying monitoring updates...${NC}" # Create the embedded monitoring HTML in app.py cat >> app.py << 'EOF' # Embedded monitoring HTML for HuggingFace Spaces MONITORING_HTML_EMBEDDED = """ πŸ“Š CIDADΓƒO.AI - Monitoring Dashboard

πŸ“Š CIDADΓƒO.AI - Monitoring Dashboard

Monitoramento em tempo real - HuggingFace Spaces

πŸ›οΈ Status

βœ… Online
HuggingFace Spaces

πŸ” InvestigaΓ§Γ΅es

--
Total realizado

🚨 Anomalias

--
Detectadas

πŸ€– Agentes

1
Zumbi Ativo
""" EOF # Update the monitoring endpoint to use embedded HTML echo -e "${YELLOW}πŸ“ Updating monitoring endpoint...${NC}" sed -i 's/from monitoring_embedded import MONITORING_HTML/# Use embedded HTML/g' app.py sed -i 's/return HTMLResponse(content=MONITORING_HTML)/return HTMLResponse(content=MONITORING_HTML_EMBEDDED)/g' app.py # Remove the import line if it exists sed -i '/import monitoring_embedded/d' app.py # Commit changes echo -e "${YELLOW}πŸ’Ύ Committing changes...${NC}" git add app.py git commit -m "feat: add embedded monitoring dashboard for HF Spaces - Add /monitoring endpoint with visual dashboard - Embedded HTML to avoid import issues - Real-time metrics visualization - Auto-refresh functionality" # Push to HuggingFace echo -e "${YELLOW}πŸš€ Pushing to HuggingFace...${NC}" git push huggingface main # Return to original branch echo -e "${YELLOW}πŸ”„ Returning to $CURRENT_BRANCH branch...${NC}" git checkout $CURRENT_BRANCH # Restore stashed changes echo -e "${YELLOW}πŸ’Ύ Restoring stashed changes...${NC}" git stash pop || true echo -e "${GREEN}================================================${NC}" echo -e "${GREEN}βœ… Monitoring update complete!${NC}" echo -e "${GREEN}================================================${NC}" echo -e "\n${YELLOW}πŸ“Š Check the monitoring at:${NC}" echo -e "${GREEN}https://neural-thinker-cidadao-ai-backend.hf.space/monitoring${NC}" echo -e "\n${YELLOW}πŸ“ˆ Raw metrics at:${NC}" echo -e "${GREEN}https://neural-thinker-cidadao-ai-backend.hf.space/metrics${NC}"