File size: 6,655 Bytes
4a0fa9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

# NEBULA EMERGENT - Deployment Script for Hugging Face Spaces
# Author: Francisco Angulo de Lafuente
# This script helps deploy the NEBULA EMERGENT system to Hugging Face Spaces

echo "🌌 NEBULA EMERGENT - Hugging Face Space Deployment Script"
echo "========================================================="

# Configuration
SPACE_NAME="nebula-emergent"
HF_USERNAME="Agnuxo"
SPACE_URL="https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Function to print colored output
print_status() {
    echo -e "${GREEN}βœ… $1${NC}"
}

print_error() {
    echo -e "${RED}❌ $1${NC}"
}

print_info() {
    echo -e "${BLUE}ℹ️  $1${NC}"
}

print_warning() {
    echo -e "${YELLOW}⚠️  $1${NC}"
}

# Check if git is installed
if ! command -v git &> /dev/null; then
    print_error "Git is not installed. Please install git first."
    exit 1
fi

# Check if huggingface-cli is installed
if ! command -v huggingface-cli &> /dev/null; then
    print_warning "huggingface-cli is not installed."
    echo "Installing huggingface-hub..."
    pip install huggingface-hub
fi

# Step 1: Login to Hugging Face
print_info "Step 1: Logging in to Hugging Face..."
echo "Please make sure you're logged in to Hugging Face."
echo "If not logged in, run: huggingface-cli login"
read -p "Press Enter to continue..."

# Step 2: Clone or create the Space repository
print_info "Step 2: Setting up Space repository..."

if [ -d "$SPACE_NAME" ]; then
    print_warning "Directory $SPACE_NAME already exists."
    read -p "Do you want to remove it and start fresh? (y/n): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        rm -rf "$SPACE_NAME"
        print_status "Removed existing directory."
    else
        cd "$SPACE_NAME"
        git pull
        print_status "Updated existing repository."
    fi
fi

if [ ! -d "$SPACE_NAME" ]; then
    print_info "Cloning Space repository..."
    git clone "https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" 2>/dev/null
    
    if [ $? -ne 0 ]; then
        print_warning "Space doesn't exist. Creating new Space..."
        mkdir "$SPACE_NAME"
        cd "$SPACE_NAME"
        git init
        git remote add origin "https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
        print_status "Initialized new repository."
    else
        cd "$SPACE_NAME"
        print_status "Cloned existing Space."
    fi
else
    cd "$SPACE_NAME"
fi

# Step 3: Copy files
print_info "Step 3: Copying project files..."

# Create the files if they don't exist in the parent directory
if [ ! -f "../app.py" ]; then
    print_error "app.py not found in parent directory!"
    print_info "Please ensure app.py is in the same directory as this script."
    exit 1
fi

cp ../app.py ./app.py
cp ../requirements.txt ./requirements.txt
cp ../README.md ./README.md

print_status "Files copied successfully."

# Step 4: Create .gitignore
print_info "Step 4: Creating .gitignore..."
cat > .gitignore << 'EOF'
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
.env
.venv
env/
venv/
ENV/
.DS_Store
*.log
flagged/
gradio_cached_examples/
EOF

print_status ".gitignore created."

# Step 5: Verify file structure
print_info "Step 5: Verifying file structure..."
echo "Current files in Space directory:"
ls -la

# Step 6: Add and commit files
print_info "Step 6: Committing files to git..."
git add .
git commit -m "πŸš€ Deploy NEBULA EMERGENT - Physical Neural Computing System

- Complete implementation with 1M+ neuron simulation
- Gravitational dynamics, photon propagation, quantum effects
- Interactive Gradio interface with 3D visualization
- Problem solving capabilities (TSP, pattern recognition)
- Real-time metrics and data export

Author: Francisco Angulo de Lafuente"

print_status "Files committed."

# Step 7: Push to Hugging Face
print_info "Step 7: Pushing to Hugging Face Spaces..."
print_warning "This may take a few minutes..."

git push origin main 2>/dev/null || git push origin master 2>/dev/null

if [ $? -eq 0 ]; then
    print_status "Successfully pushed to Hugging Face!"
    echo
    print_info "πŸŽ‰ Your Space is being built and will be available at:"
    echo -e "${GREEN}$SPACE_URL${NC}"
    echo
    print_info "It may take a few minutes for the Space to build and start."
    print_info "You can check the build logs on the Hugging Face website."
else
    print_error "Failed to push. You may need to:"
    echo "1. Run: huggingface-cli login"
    echo "2. Create the Space manually at: https://huggingface.co/new-space"
    echo "3. Then run this script again"
fi

# Step 8: Create local test script
print_info "Step 8: Creating local test script..."
cat > ../test_local.py << 'EOF'
#!/usr/bin/env python3
"""
Local test script for NEBULA EMERGENT
Run this to test the system locally before deploying
"""

import subprocess
import sys

print("πŸ§ͺ Testing NEBULA EMERGENT locally...")
print("=" * 50)

# Check Python version
print(f"Python version: {sys.version}")

# Check required packages
required = ['gradio', 'numpy', 'scipy', 'pandas', 'plotly', 'scikit-learn', 'numba']
missing = []

for package in required:
    try:
        __import__(package)
        print(f"βœ… {package} is installed")
    except ImportError:
        print(f"❌ {package} is missing")
        missing.append(package)

if missing:
    print("\n⚠️  Installing missing packages...")
    subprocess.run([sys.executable, "-m", "pip", "install"] + missing)

print("\nπŸš€ Starting local server...")
print("Open http://localhost:7860 in your browser")
print("Press Ctrl+C to stop\n")

# Run the app
subprocess.run([sys.executable, "app.py"])
EOF

chmod +x ../test_local.py
print_status "Local test script created: test_local.py"

# Final summary
echo
echo "========================================================="
print_status "🎊 Deployment script completed!"
echo
echo "πŸ“‹ Summary:"
echo "  - Space Name: $SPACE_NAME"
echo "  - Username: $HF_USERNAME"
echo "  - URL: $SPACE_URL"
echo
echo "πŸ“ Next steps:"
echo "  1. Visit your Space URL to see it in action"
echo "  2. Check the logs if the build fails"
echo "  3. Run ./test_local.py to test locally"
echo
echo "🌟 Tips:"
echo "  - The first build may take 5-10 minutes"
echo "  - If you see errors, check the build logs on HF"
echo "  - You can update the Space by running this script again"
echo
print_info "Thank you for using NEBULA EMERGENT!"
echo "========================================================="