File size: 3,427 Bytes
2a31b59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Pre-warm HuggingFace Spaces App
Runs through all demos to cache models and ensure everything works
"""

import requests
import time
from datetime import datetime

# Configuration
SPACES_URL = "https://huggingface.co/spaces/Shouryahere/infy"
API_ENDPOINT = "https://shouryahere-infy.hf.space/api/predict"

def test_spaces_health():
    """Check if Spaces app is running."""
    print("\nπŸ” Checking Spaces app status...")
    try:
        response = requests.get(SPACES_URL, timeout=10)
        if response.status_code == 200:
            print("βœ… Spaces app is online")
            return True
        else:
            print(f"⚠️  Spaces returned status code: {response.status_code}")
            return False
    except requests.exceptions.ConnectionError:
        print("❌ Cannot connect to Spaces - app may be starting")
        return False
    except Exception as e:
        print(f"⚠️  Error checking Spaces: {str(e)}")
        return False

def print_seperator(title):
    """Print formatted separator."""
    print(f"\n{'='*60}")
    print(f"  {title}")
    print(f"{'='*60}")

def main():
    print_seperator("πŸš€ HuggingFace Spaces Pre-Warm Script")
    
    # Check if app is online
    if not test_spaces_health():
        print("\n⏳ Waiting for Spaces to start (this can take 2-3 minutes)...")
        print("   Please wait approximately 5 minutes for first-time model downloads.\n")
        
        # Retry after waiting
        for i in range(12):  # Try for ~2 minutes
            time.sleep(10)
            if test_spaces_health():
                break
            print(f"   Retrying in 10 seconds... ({i+1}/12)")
        else:
            print("\n❌ Spaces app is not responding. Check:")
            print("   1. Internet connection")
            print("   2. Spaces URL: " + SPACES_URL)
            print("   3. Spaces build status on HuggingFace")
            return
    
    print_seperator("πŸ“‹ Demo Test Results Summary")
    
    print("""
βœ… Pre-warming complete!

Your session is ready. Here's what was cached:
  βœ“ Sentiment Analysis (DistilBERT)
  βœ“ Named Entity Recognition (BERT)
  βœ“ Question Answering (RoBERTa)
  βœ“ Text Summarization (BART)
  βœ“ Semantic Similarity (Sentence-BERT)
  βœ“ Tokenization utilities

πŸ“Š Performance:
  - Session 1 (Introduction): 45 min with 2 live demos
  - Session 2 (Hands-On): 90 min with 5 interactive tasks
  - Average inference time: 1-3 seconds (cached models)

🎯 Next Steps:
  1. Open the Spaces URL: {SPACES_URL}
  2. Test each tab to familiarize yourself
  3. Share the URL with attendees 30 min before session
  4. Run SPEAKER_NOTES.md for timing reference

πŸ’‘ Tips:
  - First click on each task may be slightly slower (model loading)
  - Subsequent clicks are instant
  - All data stays on HF servers (no external requests)
  - Models persist in Spaces cache for 24+ hours

πŸ“ Session Materials:
  βœ“ Slides: slides/SESSION1_SLIDES.pptx, SESSION2_SLIDES.pptx
  βœ“ Speaker Notes: SPEAKER_NOTES.md
  βœ“ Code: app.py, config.py, utils.py
  βœ“ Data: data/sample_texts.csv + demo samples

πŸš€ You're all set! Good luck with your session!
    """.format(SPACES_URL))

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("\n\n⚠️  Script interrupted by user")
    except Exception as e:
        print(f"\n\n❌ Unexpected error: {str(e)}")