import os
import shutil
import subprocess
# Paths
flutter_dir = os.path.join("UI", "safespace")
build_dir = os.path.join(flutter_dir, "build", "web")
temp_dir = os.path.join(flutter_dir, "build", "web_temp")
def main():
print("[SafeSpace] Starting Web Build & Landing Page Restructuring...")
# 1. Build the Flutter Web application with base-href /app/
print("[SafeSpace] Step 1: Compiling Flutter Web app with base-href /app/...")
try:
subprocess.run(
["flutter", "build", "web", "--release", "--base-href", "/app/"],
cwd=flutter_dir,
shell=True,
check=True
)
except subprocess.CalledProcessError as e:
print(f"[-] Flutter build failed: {e}")
return
# 2. Restructuring built files to live in an /app/ subdirectory
print("[SafeSpace] Step 2: Restructuring directories for Netlify deployment...")
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir)
os.makedirs(temp_dir)
# Move all built files into /app/ folder inside temp_dir
app_dir = os.path.join(temp_dir, "app")
os.makedirs(app_dir)
for item in os.listdir(build_dir):
src = os.path.join(build_dir, item)
dst = os.path.join(app_dir, item)
shutil.move(src, dst)
# Swap build_dir and temp_dir
shutil.rmtree(build_dir)
shutil.move(temp_dir, build_dir)
# 3. Write the beautiful custom landing page index.html to the root of the build
print("[SafeSpace] Step 3: Generating premium landing page index.html...")
landing_page_html = """
SafeSpace - Your AI-Powered Mental Health Sanctuary
SafeSpace
AI-Powered Psychological Assistant
Your Intelligent Mental Wellness Sanctuary
Empowering emotional self-awareness through multi-modal AI clinical scoring (DASS-42), bilingual dialect natural language analysis, and dynamic root-cause isolation.
📊
Clinical Psychometrics
Fully integrated DASS-42 clinical self-assessment scale evaluating separate subscale classifications for depression, anxiety, and stress levels.
🧠
Bilingual NLP Analysis
Advanced XLM-RoBERTa sentiment engine that automatically processes, translates, and classifies raw journal texts in English and Arabic dialects.
🔍
Root-Stressor Extraction
Scans assessment texts to isolate primary distress domains (Workplace, Academic, Social, Financial, Relationships) and match you with specialized exercises.
🛡️
Bilingual Crisis Safety Net
Deterministic realtime safety override that scans inputs for critical markers, instantly bypassing AI pipelines to deliver immediate emergency assistance.
🧘
Therapeutic Grounding
Features animated box breathing pacing, gamified 5-4-3-2-1 sensory exercises, meditation timers, and quick stress-relief mini-games.
🔄
Multi-Modal Fusion
Intelligently balances subjective survey responses and free-text entries (60/40 ratio) to construct a comprehensive wellness profile.
Begin Your Wellness Journey
Access the platform instantly via the web application or download client packages, demonstration slides, and project documentation.
"""
with open(os.path.join(build_dir, "index.html"), "w", encoding="utf-8") as f:
f.write(landing_page_html)
# 4. Write Netlify _redirects file to the root build directory
print("[SafeSpace] Step 4: Creating Netlify routing configuration (_redirects)...")
redirects_content = """/app/* /app/index.html 200
/* /index.html 200
"""
with open(os.path.join(build_dir, "_redirects"), "w", encoding="utf-8") as f:
f.write(redirects_content)
print("\n[SafeSpace] Web build successfully structured and ready for Netlify!")
print(f"[SafeSpace] Deployment directory: {os.path.abspath(build_dir)}")
print("[SafeSpace] Upload the folder above to Netlify to publish both your landing page and Web App!")
if __name__ == "__main__":
main()