tryonapi / test_deployment.py
dawoodshahzad0707's picture
Upload 10 files
783eac3 verified
"""
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())