Spaces:
Running
on
Zero
Running
on
Zero
File size: 5,886 Bytes
783eac3 |
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 |
"""
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())
|