Spaces:
Sleeping
Sleeping
File size: 6,169 Bytes
92ea014 |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
#!/usr/bin/env python3
"""
Test script to verify deployment readiness for Theorem Explanation Agent
"""
import os
import sys
import traceback
from pathlib import Path
def test_imports():
"""Test if all required imports work."""
print("Testing imports...")
try:
import gradio as gr
print("β
Gradio imported successfully")
print(f" Version: {gr.__version__}")
except ImportError as e:
print(f"β Failed to import Gradio: {e}")
return False
try:
import numpy as np
print("β
NumPy imported successfully")
except ImportError as e:
print(f"β Failed to import NumPy: {e}")
return False
try:
import requests
print("β
Requests imported successfully")
except ImportError as e:
print(f"β Failed to import Requests: {e}")
return False
# Test optional dependencies
try:
import manim
print("β
Manim imported successfully")
except ImportError:
print("β οΈ Manim not available - will run in demo mode")
return True
def test_app_functionality():
"""Test if the app can be imported and basic functions work."""
print("\nTesting app functionality...")
try:
# Set demo mode for testing
os.environ["DEMO_MODE"] = "true"
# Import app components
sys.path.insert(0, str(Path(__file__).parent))
from app import (
initialize_video_generator,
simulate_video_generation,
list_available_models,
get_example_topics
)
print("β
App components imported successfully")
# Test initialization
init_result = initialize_video_generator()
print(f" Initialization: {init_result}")
# Test simulation
sim_result = simulate_video_generation("test topic", "test context", 3)
print(f" Simulation result: {sim_result['success']}")
# Test model listing
models = list_available_models()
print(f" Available models: {len(models)} models")
# Test examples
examples = get_example_topics()
print(f" Example topics: {len(examples)} examples")
print("β
Basic app functionality works")
return True
except Exception as e:
print(f"β App functionality test failed: {e}")
traceback.print_exc()
return False
def test_gradio_interface():
"""Test if Gradio interface can be created."""
print("\nTesting Gradio interface...")
try:
os.environ["DEMO_MODE"] = "true"
from app import create_gradio_interface, create_api_endpoints
# Test main interface creation
interface = create_gradio_interface()
print("β
Main Gradio interface created successfully")
# Test API interface creation
api_interface = create_api_endpoints()
print("β
API interface created successfully")
return True
except Exception as e:
print(f"β Gradio interface test failed: {e}")
traceback.print_exc()
return False
def test_environment():
"""Test environment variables and configuration."""
print("\nTesting environment...")
# Check demo mode
demo_mode = os.getenv("DEMO_MODE", "false").lower() == "true"
print(f" Demo mode: {demo_mode}")
# Check for API keys (optional)
api_keys = {
"GEMINI_API_KEY": os.getenv("GEMINI_API_KEY"),
"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY"),
"ELEVENLABS_API_KEY": os.getenv("ELEVENLABS_API_KEY")
}
for key, value in api_keys.items():
if value:
print(f" {key}: β
Set")
else:
print(f" {key}: β οΈ Not set (demo mode will work)")
# Check Python version
python_version = sys.version_info
print(f" Python version: {python_version.major}.{python_version.minor}.{python_version.micro}")
if python_version >= (3, 8):
print("β
Python version is compatible")
else:
print("β Python version too old (requires 3.8+)")
return False
return True
def main():
"""Run all tests."""
print("π§ͺ Testing Theorem Explanation Agent Deployment Readiness\n")
tests = [
("Environment", test_environment),
("Imports", test_imports),
("App Functionality", test_app_functionality),
("Gradio Interface", test_gradio_interface)
]
results = []
for test_name, test_func in tests:
print(f"\n{'='*50}")
print(f"Running {test_name} test...")
print("="*50)
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f"β {test_name} test crashed: {e}")
results.append((test_name, False))
# Summary
print(f"\n{'='*50}")
print("TEST SUMMARY")
print("="*50)
all_passed = True
for test_name, result in results:
status = "β
PASS" if result else "β FAIL"
print(f"{test_name}: {status}")
if not result:
all_passed = False
print(f"\n{'='*50}")
if all_passed:
print("π ALL TESTS PASSED - Ready for deployment!")
print("\nπ Deployment Instructions:")
print("1. Push code to GitHub repository")
print("2. Create new Hugging Face Space")
print("3. Connect to your repository")
print("4. Set DEMO_MODE=false in Space settings (if you have API keys)")
print("5. Add API keys as Space secrets (optional)")
print("6. Deploy and test!")
else:
print("β SOME TESTS FAILED - Fix issues before deployment")
print("\nπ§ Recommended actions:")
print("- Install missing dependencies")
print("- Fix import errors")
print("- Ensure Python 3.8+ is being used")
return all_passed
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |