#!/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)}")