File size: 3,150 Bytes
e5f2dfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Script to check for potential runtime errors before deployment"""

import sys
import os

print("=" * 60)
print("Runtime Error Checker for Hugging Face Space")
print("=" * 60)

errors = []
warnings = []

# Check 1: Python syntax
print("\n1. Checking Python syntax...")
try:
    compile(open('app.py').read(), 'app.py', 'exec')
    print("   βœ“ app.py syntax is valid")
except SyntaxError as e:
    errors.append(f"Syntax error in app.py: {e}")
    print(f"   βœ— Syntax error: {e}")

# Check 2: Required files
print("\n2. Checking required files...")
required_files = [
    'app.py',
    'requirements.txt',
    'Dockerfile',
    'templates/base.html',
    'static/css/style.css'
]
for file in required_files:
    if os.path.exists(file):
        print(f"   βœ“ {file} exists")
    else:
        errors.append(f"Missing required file: {file}")
        print(f"   βœ— {file} missing")

# Check 3: Required directories
print("\n3. Checking required directories...")
required_dirs = [
    'templates',
    'static',
    'static/css',
    'apps.err/material_detection_naturalobjects'
]
for dir_path in required_dirs:
    if os.path.exists(dir_path):
        print(f"   βœ“ {dir_path} exists")
    else:
        errors.append(f"Missing required directory: {dir_path}")
        print(f"   βœ— {dir_path} missing")

# Check 4: Import checks
print("\n4. Checking critical imports...")
try:
    import flask
    print("   βœ“ flask imported")
except ImportError as e:
    errors.append(f"Cannot import flask: {e}")
    print(f"   βœ— flask import failed: {e}")

try:
    import torch
    print("   βœ“ torch imported")
except ImportError as e:
    warnings.append(f"Cannot import torch (may not be critical at startup): {e}")
    print(f"   ⚠ torch import failed (may be OK): {e}")

# Check 5: Port configuration
print("\n5. Checking port configuration...")
with open('app.py', 'r') as f:
    content = f.read()
    if 'port = 7860' in content or 'port=7860' in content:
        print("   βœ“ Port 7860 configured for Hugging Face")
    else:
        warnings.append("Port 7860 may not be configured correctly")
        print("   ⚠ Port configuration may need checking")

# Check 6: SPACE_ID handling
print("\n6. Checking SPACE_ID handling...")
if 'SPACE_ID' in content:
    print("   βœ“ SPACE_ID environment variable handling found")
else:
    warnings.append("SPACE_ID handling not found")
    print("   ⚠ SPACE_ID handling not found")

# Summary
print("\n" + "=" * 60)
print("SUMMARY")
print("=" * 60)
if errors:
    print(f"\n❌ ERRORS FOUND ({len(errors)}):")
    for error in errors:
        print(f"   - {error}")
else:
    print("\nβœ“ No critical errors found")

if warnings:
    print(f"\n⚠ WARNINGS ({len(warnings)}):")
    for warning in warnings:
        print(f"   - {warning}")
else:
    print("\nβœ“ No warnings")

print("\n" + "=" * 60)
print("To check runtime errors on Hugging Face:")
print("1. Go to https://huggingface.co/spaces/mvplus/spad_for_vision")
print("2. Click on the 'Logs' tab")
print("3. Look for error messages in the build or runtime logs")
print("=" * 60)

sys.exit(1 if errors else 0)