File size: 8,121 Bytes
bf961d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env python3
"""
HuggingFace Spaces Pre-Deployment Validation Script
Validates the LifeUnity AI Cognitive Twin System before deployment
"""

import os
import sys
from pathlib import Path

print("="*60)
print("HuggingFace Spaces Pre-Deployment Validation")
print("LifeUnity AI β€” Cognitive Twin System")
print("="*60)
print()

# STEP 1: Verify Project Structure
print("βœ… STEP 1: VERIFY PROJECT STRUCTURE")
print("-" * 60)

required_dirs = [
    "app",
    "app/utils",
    "data",
    "logs"
]

required_files = [
    "app/main.py",
    "app/mood_detection.py",
    "app/memory_graph.py",
    "app/insights_engine.py",
    "app/user_profile.py",
    "app/utils/preprocess.py",
    "app/utils/embedder.py",
    "app/utils/logger.py",
    "requirements.txt",
    "HF_README.md"
]

all_dirs_ok = True
for dir_path in required_dirs:
    if Path(dir_path).exists():
        print(f"  βœ“ {dir_path}/")
    else:
        print(f"  βœ— {dir_path}/ - MISSING")
        all_dirs_ok = False

print()

all_files_ok = True
for file_path in required_files:
    if Path(file_path).exists():
        size = Path(file_path).stat().st_size
        print(f"  βœ“ {file_path} ({size} bytes)")
    else:
        print(f"  βœ— {file_path} - MISSING")
        all_files_ok = False

print()

if all_dirs_ok and all_files_ok:
    print("βœ… Structure validation PASSED")
else:
    print("❌ Structure validation FAILED")
    sys.exit(1)

print()

# STEP 2: Validate Streamlit App Entrypoint
print("βœ… STEP 2: VALIDATE STREAMLIT APP ENTRYPOINT")
print("-" * 60)

if Path("app/main.py").exists():
    with open("app/main.py", "r") as f:
        content = f.read()
        if "import streamlit" in content or "from streamlit" in content:
            print("  βœ“ app/main.py contains Streamlit imports")
        else:
            print("  βœ— app/main.py missing Streamlit imports")
            sys.exit(1)
        
        if "st.set_page_config" in content:
            print("  βœ“ app/main.py has page configuration")
        else:
            print("  ⚠ app/main.py missing page configuration")
    
    print("  βœ“ Entrypoint: app/main.py (as specified in HF_README.md)")
else:
    print("  βœ— app/main.py NOT FOUND")
    sys.exit(1)

print()
print("βœ… Entrypoint validation PASSED")
print()

# STEP 3: Verify Dependencies
print("βœ… STEP 3: VERIFY DEPENDENCIES")
print("-" * 60)

required_packages = [
    "streamlit",
    "torch",
    "transformers",
    "sentence-transformers",
    "opencv-python-headless",
    "numpy",
    "pandas",
    "pillow",  # Case-insensitive match
    "scikit-learn",
    "networkx",
    "fer",
    "tensorflow",
    "plotly",
    "matplotlib"
]

if Path("requirements.txt").exists():
    with open("requirements.txt", "r") as f:
        requirements_content = f.read().lower()
    
    missing_packages = []
    for package in required_packages:
        if package.lower().replace("-", "_") in requirements_content.replace("-", "_"):
            print(f"  βœ“ {package}")
        else:
            print(f"  βœ— {package} - MISSING")
            missing_packages.append(package)
    
    if missing_packages:
        print()
        print(f"❌ Missing packages: {', '.join(missing_packages)}")
        sys.exit(1)
    else:
        print()
        print("βœ… Dependencies validation PASSED")
else:
    print("  βœ— requirements.txt NOT FOUND")
    sys.exit(1)

print()

# STEP 4: Configure HuggingFace Space
print("βœ… STEP 4: CONFIGURE HUGGINGFACE SPACE")
print("-" * 60)

if Path("HF_README.md").exists():
    with open("HF_README.md", "r") as f:
        hf_content = f.read()
    
    if "sdk: streamlit" in hf_content:
        print("  βœ“ SDK set to Streamlit")
    else:
        print("  βœ— SDK not set to Streamlit")
        sys.exit(1)
    
    if "app_file: app/main.py" in hf_content:
        print("  βœ“ app_file points to app/main.py")
    else:
        print("  ⚠ app_file not explicitly set (will default to app.py)")
    
    if "gradio" not in hf_content.lower():
        print("  βœ“ No Gradio configuration found")
    else:
        print("  ⚠ Gradio references found in config")
    
    print()
    print("βœ… HuggingFace Space configuration PASSED")
else:
    print("  βœ— HF_README.md NOT FOUND")
    sys.exit(1)

print()

# STEP 5: Run Build Health Check
print("βœ… STEP 5: RUN BUILD HEALTH CHECK")
print("-" * 60)

# Check Python syntax
import py_compile
syntax_errors = []

for file_path in required_files:
    if file_path.endswith(".py"):
        try:
            py_compile.compile(file_path, doraise=True)
            print(f"  βœ“ {file_path} - syntax OK")
        except py_compile.PyCompileError as e:
            print(f"  βœ— {file_path} - syntax ERROR")
            syntax_errors.append(file_path)

print()

if syntax_errors:
    print(f"❌ Syntax errors in: {', '.join(syntax_errors)}")
    sys.exit(1)

# Check for webcam/camera code
print("  Checking for webcam/camera code...")
webcam_issues = []
webcam_check_files = [f for f in required_files if f.endswith("main.py") or f.endswith("mood_detection.py")]
for file_path in webcam_check_files:
    if Path(file_path).exists():
        with open(file_path, "r") as f:
            content = f.read()
            if "camera_input" in content:
                webcam_issues.append(f"{file_path} contains camera_input")
            if "VideoCapture" in content:
                webcam_issues.append(f"{file_path} contains VideoCapture")

if webcam_issues:
    print()
    for issue in webcam_issues:
        print(f"  βœ— {issue}")
    print("❌ Webcam code found (not compatible with HF Spaces)")
    sys.exit(1)
else:
    print("  βœ“ No webcam code found (HF Spaces compatible)")

print()

# Check imports
print("  Checking relative imports...")
import_issues = []
for file_path in required_files:
    if file_path.endswith(".py") and file_path != "app/main.py":
        with open(file_path, "r") as f:
            content = f.read()
            # Check for relative imports from app
            if "from app." in content:
                print(f"  βœ“ {file_path} uses relative imports")
            elif "import" in content and file_path.startswith("app/"):
                # Check if it at least imports from app.utils
                if "from app.utils" in content:
                    print(f"  βœ“ {file_path} uses relative imports")
                else:
                    import_issues.append(file_path)

if import_issues:
    print()
    print(f"  ⚠ Check imports in: {', '.join(import_issues)}")

print()

# Check data directory
if Path("data").exists():
    print("  βœ“ data/ directory exists (for JSON storage)")
else:
    print("  ⚠ data/ directory will be created at runtime")

print()
print("βœ… Build health check PASSED")
print()

# STEP 6: Deployment Readiness Report
print("="*60)
print("βœ… DEPLOYMENT READINESS REPORT")
print("="*60)
print()
print("Project: LifeUnity AI β€” Cognitive Twin System")
print("Status: βœ… READY FOR HUGGINGFACE SPACES DEPLOYMENT")
print()
print("Configuration:")
print("  β€’ SDK: Streamlit")
print("  β€’ Entry Point: app/main.py")
print("  β€’ Hardware: CPU Basic (free tier)")
print("  β€’ Visibility: Public")
print()
print("Pages Available:")
print("  1. βœ… Dashboard - Metrics & trends")
print("  2. βœ… Emotion Detection - Image upload only")
print("  3. βœ… Cognitive Memory - Notes with embeddings")
print("  4. βœ… AI Insights - Wellness reports")
print()
print("Features:")
print("  β€’ βœ… No webcam code (HF Spaces compatible)")
print("  β€’ βœ… Image upload for emotion detection")
print("  β€’ βœ… Sentence-BERT embeddings (all-MiniLM-L6-v2)")
print("  β€’ βœ… Local rule-based AI insights (no API keys)")
print("  β€’ βœ… JSON storage in /data directory")
print("  β€’ βœ… All dependencies cloud-safe")
print()
print("Next Steps:")
print("  1. Create Space on HuggingFace")
print("  2. Select Streamlit SDK")
print("  3. Upload project files")
print("  4. Rename HF_README.md to README.md")
print("  5. Space will auto-deploy in 5-10 minutes")
print()
print("="*60)
print("βœ… ALL VALIDATION CHECKS PASSED")
print("="*60)