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