Spaces:
Paused
Paused
File size: 6,921 Bytes
922c3ba |
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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
#!/usr/bin/env python3
"""
Deployment Validation Script for Hugging Face Spaces
===================================================
This script validates the essential components needed for successful deployment.
"""
import os
import sys
from pathlib import Path
import json
def check_file_structure():
"""Check that all required files exist for deployment"""
print("π Checking file structure...")
required_files = [
"huggingface_space/app.py",
"huggingface_space/Spacefile",
"huggingface_space/README.md",
"requirements.txt",
"app/services/ocr_service.py",
"app/services/ai_service.py",
"app/services/database_service.py",
"app/models/document_models.py",
"data/sample_persian.pdf"
]
missing_files = []
for file_path in required_files:
if not os.path.exists(file_path):
missing_files.append(file_path)
else:
print(f"β
{file_path}")
if missing_files:
print(f"\nβ Missing files: {missing_files}")
return False
else:
print("\nβ
All required files exist")
return True
def check_requirements():
"""Check requirements.txt for deployment compatibility"""
print("\nπ Checking requirements.txt...")
try:
with open("requirements.txt", "r") as f:
requirements = f.read()
# Check for essential packages
essential_packages = [
"gradio",
"transformers",
"torch",
"fastapi",
"uvicorn",
"PyMuPDF",
"Pillow"
]
missing_packages = []
for package in essential_packages:
if package not in requirements:
missing_packages.append(package)
if missing_packages:
print(f"β Missing packages: {missing_packages}")
return False
else:
print("β
All essential packages found in requirements.txt")
return True
except Exception as e:
print(f"β Error reading requirements.txt: {e}")
return False
def check_spacefile():
"""Check Spacefile configuration"""
print("\nπ Checking Spacefile...")
try:
with open("huggingface_space/Spacefile", "r") as f:
spacefile_content = f.read()
# Check for essential configurations
required_configs = [
"runtime: python",
"run: python app.py",
"gradio"
]
missing_configs = []
for config in required_configs:
if config not in spacefile_content:
missing_configs.append(config)
if missing_configs:
print(f"β Missing configurations: {missing_configs}")
return False
else:
print("β
Spacefile properly configured")
return True
except Exception as e:
print(f"β Error reading Spacefile: {e}")
return False
def check_app_entry_point():
"""Check the main app.py entry point"""
print("\nπ Checking app.py entry point...")
try:
with open("huggingface_space/app.py", "r") as f:
app_content = f.read()
# Check for essential components
required_components = [
"import gradio",
"gr.Blocks",
"demo.launch"
]
missing_components = []
for component in required_components:
if component not in app_content:
missing_components.append(component)
if missing_components:
print(f"β Missing components: {missing_components}")
return False
else:
print("β
App entry point properly configured")
return True
except Exception as e:
print(f"β Error reading app.py: {e}")
return False
def check_sample_data():
"""Check that sample data exists"""
print("\nπ Checking sample data...")
sample_files = [
"data/sample_persian.pdf"
]
missing_files = []
for file_path in sample_files:
if not os.path.exists(file_path):
missing_files.append(file_path)
else:
file_size = os.path.getsize(file_path)
print(f"β
{file_path} ({file_size} bytes)")
if missing_files:
print(f"β Missing sample files: {missing_files}")
return False
else:
print("β
Sample data available")
return True
def generate_deployment_summary():
"""Generate deployment summary"""
print("\nπ Deployment Summary")
print("=" * 50)
summary = {
"project_name": "Legal Dashboard OCR",
"deployment_type": "Hugging Face Spaces",
"framework": "Gradio",
"entry_point": "huggingface_space/app.py",
"requirements": "requirements.txt",
"configuration": "huggingface_space/Spacefile",
"documentation": "huggingface_space/README.md",
"sample_data": "data/sample_persian.pdf"
}
for key, value in summary.items():
print(f"{key.replace('_', ' ').title()}: {value}")
return summary
def main():
"""Main validation function"""
print("π Legal Dashboard OCR - Deployment Validation")
print("=" * 60)
# Run all checks
checks = [
check_file_structure,
check_requirements,
check_spacefile,
check_app_entry_point,
check_sample_data
]
results = []
for check in checks:
try:
result = check()
results.append(result)
except Exception as e:
print(f"β Check failed with exception: {e}")
results.append(False)
# Generate summary
summary = generate_deployment_summary()
# Final results
print("\n" + "=" * 60)
print("π Validation Results")
print("=" * 60)
passed = sum(results)
total = len(results)
print(f"β
Passed: {passed}/{total}")
print(f"β Failed: {total - passed}/{total}")
if all(results):
print("\nπ All validation checks passed!")
print("β
Project is ready for Hugging Face Spaces deployment")
print("\nπ Next Steps:")
print("1. Create a new Space on Hugging Face")
print("2. Upload the huggingface_space/ directory")
print("3. Set HF_TOKEN environment variable")
print("4. Deploy and test the application")
return 0
else:
print("\nβ οΈ Some validation checks failed.")
print("Please fix the issues above before deployment.")
return 1
if __name__ == "__main__":
sys.exit(main())
|