Skip to content

Keep Hugging Face Spaces Awake #536

Keep Hugging Face Spaces Awake

Keep Hugging Face Spaces Awake #536

name: Keep Hugging Face Spaces Awake
on:
schedule:
# Runs every hour at :00 UTC
# = every hour at :30 IST
- cron: "0 * * * *"
workflow_dispatch:
jobs:
access-hugging-face-spaces:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# ==========================================
# CHECKOUT REPOSITORY
# ==========================================
- name: Checkout repository
uses: actions/checkout@v4
# ==========================================
# INSTALL AGENT-BROWSER
# ==========================================
- name: Install agent-browser
run: npm install -g agent-browser
# ==========================================
# INSTALL PLAYWRIGHT BROWSERS
# ==========================================
- name: Install Playwright browsers
run: agent-browser install --with-deps
# ==========================================
# HUGGING FACE SPACE 1 - SWEETY
# ==========================================
- name: Check Hugging Face Space 1 - Sweety
run: |
set -e
echo "=========================================="
echo "πŸ€– CHECKING HUGGING FACE SPACE 1 - SWEETY"
echo "=========================================="
# ------------------------------------------
# OPEN NORMAL HUGGING FACE URL
# ------------------------------------------
echo "🌐 Opening normal Hugging Face URL..."
agent-browser open "${{ secrets.HUGGING_FACE_SPACE_URL }}"
echo "⏳ Waiting 10 seconds..."
sleep 10
# ------------------------------------------
# SCREENSHOT 1
# ------------------------------------------
echo "πŸ“Έ Taking screenshot of normal HF page..."
agent-browser screenshot space1-normal.png
# ------------------------------------------
# CHECK FOR RESTART SPACE BUTTON
# ------------------------------------------
echo "πŸ” Checking for Restart Space button..."
if agent-browser find text "Restart Space" >/dev/null 2>&1; then
echo "πŸ”΄ Restart Space button detected!"
echo "πŸ”„ Clicking Restart Space..."
agent-browser click text "Restart Space"
echo "βœ… Restart Space clicked!"
echo "⏳ Waiting 60 seconds for Space to wake up..."
sleep 60
else
echo "🟒 Restart Space button not detected."
fi
agent-browser close
# ------------------------------------------
# OPEN DIRECT HF.SPACE URL
# ------------------------------------------
echo "=========================================="
echo "🌐 OPENING DIRECT HF.SPACE URL"
echo "=========================================="
agent-browser open "https://mythaitts-sweety.hf.space"
echo "⏳ Waiting 15 seconds..."
sleep 15
# ------------------------------------------
# SCREENSHOT 2
# ------------------------------------------
echo "πŸ“Έ Taking screenshot of direct hf.space..."
agent-browser screenshot space1-direct.png
agent-browser close
echo "βœ… Space 1 check completed!"
# ==========================================
# HUGGING FACE SPACE 2 - ITZME CV
# ==========================================
- name: Check Hugging Face Space 2 - ITZME CV
run: |
set -e
echo "=========================================="
echo "πŸ€– CHECKING HUGGING FACE SPACE 2 - ITZME CV"
echo "=========================================="
# ------------------------------------------
# OPEN NORMAL HUGGING FACE URL
# ------------------------------------------
echo "🌐 Opening normal Hugging Face URL..."
agent-browser open "${{ secrets.HUGGING_FACE_SPACE_URL_2 }}"
echo "⏳ Waiting 10 seconds..."
sleep 10
# ------------------------------------------
# SCREENSHOT 3
# ------------------------------------------
echo "πŸ“Έ Taking screenshot of normal HF page..."
agent-browser screenshot space2-normal.png
# ------------------------------------------
# CHECK FOR RESTART SPACE BUTTON
# ------------------------------------------
echo "πŸ” Checking for Restart Space button..."
if agent-browser find text "Restart Space" >/dev/null 2>&1; then
echo "πŸ”΄ Restart Space button detected!"
echo "πŸ”„ Clicking Restart Space..."
agent-browser click text "Restart Space"
echo "βœ… Restart Space clicked!"
echo "⏳ Waiting 60 seconds for Space to wake up..."
sleep 60
else
echo "🟒 Restart Space button not detected."
fi
agent-browser close
# ------------------------------------------
# OPEN DIRECT HF.SPACE URL
# ------------------------------------------
echo "=========================================="
echo "🌐 OPENING DIRECT HF.SPACE URL"
echo "=========================================="
agent-browser open "https://mythaitts-itzme-cv.hf.space"
echo "⏳ Waiting 15 seconds..."
sleep 15
# ------------------------------------------
# SCREENSHOT 4
# ------------------------------------------
echo "πŸ“Έ Taking screenshot of direct hf.space..."
agent-browser screenshot space2-direct.png
agent-browser close
echo "βœ… Space 2 check completed!"
# ==========================================
# SEND 4 SCREENSHOTS TO DISCORD
# ==========================================
- name: Notify Discord
if: always()
run: |
echo "πŸ“€ Sending screenshots to Discord..."
curl --fail-with-body -sS -X POST \
-F 'payload_json={"content":"πŸ€– Hugging Face Spaces Health Check Complete! πŸš€\n\nπŸ“¦ Space 1 β€” Sweety\n🌐 Normal HF page checked\nπŸ”— Direct hf.space checked\n\nπŸ“¦ Space 2 β€” ITZME CV\n🌐 Normal HF page checked\nπŸ”— Direct hf.space checked\n\nπŸ”„ Restart Space buttons were automatically checked."}' \
-F "file1=@space1-normal.png;type=image/png" \
-F "file2=@space1-direct.png;type=image/png" \
-F "file3=@space2-normal.png;type=image/png" \
-F "file4=@space2-direct.png;type=image/png" \
"${{ secrets.DISCORD_WEBHOOK_URL }}"
echo "βœ… Discord notification sent!"