Spaces:
Running
on
Zero
Running
on
Zero
| """ | |
| Test script for the Gradio Virtual Try-On app | |
| This script helps verify the app structure without requiring GPU | |
| """ | |
| import sys | |
| import importlib.util | |
| def test_imports(): | |
| """Test if all required packages can be imported""" | |
| print("π Testing imports...") | |
| required_packages = [ | |
| 'gradio', | |
| 'PIL', | |
| 'torch', | |
| 'diffusers', | |
| 'transformers' | |
| ] | |
| missing_packages = [] | |
| for package in required_packages: | |
| try: | |
| if package == 'PIL': | |
| __import__('PIL') | |
| else: | |
| __import__(package) | |
| print(f" β {package}") | |
| except ImportError: | |
| print(f" β {package} - NOT FOUND") | |
| missing_packages.append(package) | |
| if missing_packages: | |
| print(f"\nβ οΈ Missing packages: {', '.join(missing_packages)}") | |
| print("Run: pip install -r requirements.txt") | |
| return False | |
| else: | |
| print("\nβ All required packages are installed!") | |
| return True | |
| def test_app_structure(): | |
| """Test if app.py has correct structure""" | |
| print("\nπ Testing app.py structure...") | |
| try: | |
| with open('app.py', 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| checks = { | |
| 'import gradio': 'gradio imported', | |
| '@spaces.GPU': 'ZeroGPU decorator present', | |
| 'def virtual_tryon': 'virtual_tryon function defined', | |
| 'gr.Blocks': 'Gradio Blocks interface', | |
| 'demo.launch': 'App launch configured' | |
| } | |
| all_passed = True | |
| for check, description in checks.items(): | |
| if check in content: | |
| print(f" β {description}") | |
| else: | |
| print(f" β {description} - NOT FOUND") | |
| all_passed = False | |
| if all_passed: | |
| print("\nβ App structure looks good!") | |
| else: | |
| print("\nβ οΈ Some checks failed. Review app.py") | |
| return all_passed | |
| except FileNotFoundError: | |
| print(" β app.py not found!") | |
| return False | |
| def test_readme(): | |
| """Test if README.md has correct frontmatter""" | |
| print("\nπ Testing README.md...") | |
| try: | |
| with open('README.md', 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| if content.startswith('---'): | |
| frontmatter = content.split('---')[1] | |
| checks = { | |
| 'sdk: gradio': 'Gradio SDK specified', | |
| 'sdk_version': 'SDK version specified', | |
| 'app_file: app.py': 'App file specified' | |
| } | |
| all_passed = True | |
| for check, description in checks.items(): | |
| if check in frontmatter: | |
| print(f" β {description}") | |
| else: | |
| print(f" β {description} - NOT FOUND") | |
| all_passed = False | |
| if all_passed: | |
| print("\nβ README.md frontmatter is correct!") | |
| else: | |
| print("\nβ οΈ README.md frontmatter needs fixes") | |
| return all_passed | |
| else: | |
| print(" β README.md missing frontmatter!") | |
| return False | |
| except FileNotFoundError: | |
| print(" β README.md not found!") | |
| return False | |
| def test_requirements(): | |
| """Test if requirements.txt exists and has necessary packages""" | |
| print("\nπ Testing requirements.txt...") | |
| try: | |
| with open('requirements.txt', 'r', encoding='utf-8') as f: | |
| requirements = f.read() | |
| required = ['gradio', 'torch', 'diffusers', 'spaces'] | |
| all_present = True | |
| for package in required: | |
| if package in requirements: | |
| print(f" β {package}") | |
| else: | |
| print(f" β {package} - NOT FOUND") | |
| all_present = False | |
| if all_present: | |
| print("\nβ requirements.txt looks good!") | |
| else: | |
| print("\nβ οΈ Some required packages missing from requirements.txt") | |
| return all_present | |
| except FileNotFoundError: | |
| print(" β requirements.txt not found!") | |
| return False | |
| def main(): | |
| """Run all tests""" | |
| print("=" * 60) | |
| print("Virtual Try-On App - Pre-Deployment Tests") | |
| print("=" * 60) | |
| results = [] | |
| # Run tests | |
| results.append(("Imports", test_imports())) | |
| results.append(("App Structure", test_app_structure())) | |
| results.append(("README", test_readme())) | |
| results.append(("Requirements", test_requirements())) | |
| # Summary | |
| print("\n" + "=" * 60) | |
| print("Test Summary") | |
| print("=" * 60) | |
| all_passed = True | |
| for test_name, passed in results: | |
| status = "β PASSED" if passed else "β FAILED" | |
| print(f"{test_name}: {status}") | |
| if not passed: | |
| all_passed = False | |
| print("=" * 60) | |
| if all_passed: | |
| print("\nπ All tests passed! Ready to deploy to Hugging Face!") | |
| print("\nNext steps:") | |
| print("1. Create a new Space on Hugging Face") | |
| print("2. Choose 'Gradio' as SDK") | |
| print("3. Select 'ZeroGPU' as hardware") | |
| print("4. Upload: app.py, requirements.txt, README.md") | |
| print("5. Wait for build to complete") | |
| print("\nSee DEPLOYMENT.md for detailed instructions.") | |
| return 0 | |
| else: | |
| print("\nβ οΈ Some tests failed. Please fix the issues above.") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |