Spaces:
Paused
Paused
Ali Mohsin
commited on
Commit
Β·
fd9f634
1
Parent(s):
8d61874
more fixes
Browse files
app.py
CHANGED
|
@@ -253,7 +253,10 @@ def try_import_loop():
|
|
| 253 |
print("Attempting to import processing engine...")
|
| 254 |
|
| 255 |
# First, try to run post-install if needed
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
| 257 |
print("π Hugging Face Spaces detected - ensuring all dependencies are installed...")
|
| 258 |
try:
|
| 259 |
# Check if critical dependencies are missing
|
|
@@ -283,12 +286,77 @@ if os.environ.get('HUGGING_FACE_SPACES', '0') == '1':
|
|
| 283 |
# Try to run post_install script
|
| 284 |
try:
|
| 285 |
import subprocess
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
if
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
else:
|
| 291 |
-
print(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
except Exception as e:
|
| 293 |
print(f"β οΈ Could not run post-install script: {e}")
|
| 294 |
else:
|
|
@@ -296,7 +364,11 @@ if os.environ.get('HUGGING_FACE_SPACES', '0') == '1':
|
|
| 296 |
|
| 297 |
except Exception as e:
|
| 298 |
print(f"β οΈ Error checking dependencies: {e}")
|
|
|
|
|
|
|
| 299 |
|
|
|
|
|
|
|
| 300 |
import_success = try_import_loop()
|
| 301 |
|
| 302 |
if import_success:
|
|
@@ -313,9 +385,11 @@ else:
|
|
| 313 |
print(" - All other required packages")
|
| 314 |
|
| 315 |
# In production, we should fail fast if critical dependencies are missing
|
| 316 |
-
if
|
| 317 |
print("π¨ Production environment detected - exiting due to missing dependencies")
|
| 318 |
print("π‘ Try running: python post_install.py")
|
|
|
|
|
|
|
| 319 |
sys.exit(1)
|
| 320 |
else:
|
| 321 |
print("β οΈ Development mode - continuing with limited functionality")
|
|
|
|
| 253 |
print("Attempting to import processing engine...")
|
| 254 |
|
| 255 |
# First, try to run post-install if needed
|
| 256 |
+
print("π Checking for Hugging Face Spaces environment...")
|
| 257 |
+
is_hf_spaces = os.environ.get('HUGGING_FACE_SPACES', '0') == '1' or os.environ.get('SPACE_ID') is not None
|
| 258 |
+
|
| 259 |
+
if is_hf_spaces:
|
| 260 |
print("π Hugging Face Spaces detected - ensuring all dependencies are installed...")
|
| 261 |
try:
|
| 262 |
# Check if critical dependencies are missing
|
|
|
|
| 286 |
# Try to run post_install script
|
| 287 |
try:
|
| 288 |
import subprocess
|
| 289 |
+
print("π¦ Running post-install script...")
|
| 290 |
+
|
| 291 |
+
# Check if post_install.py exists
|
| 292 |
+
if os.path.exists("post_install.py"):
|
| 293 |
+
print("β
post_install.py found, executing...")
|
| 294 |
+
result = subprocess.run([sys.executable, "post_install.py"],
|
| 295 |
+
capture_output=True, text=True, timeout=600)
|
| 296 |
+
if result.returncode == 0:
|
| 297 |
+
print("β
Post-install script completed successfully")
|
| 298 |
+
print("Output:", result.stdout)
|
| 299 |
+
else:
|
| 300 |
+
print(f"β οΈ Post-install script failed with return code {result.returncode}")
|
| 301 |
+
print(f"Error output: {result.stderr}")
|
| 302 |
+
print(f"Standard output: {result.stdout}")
|
| 303 |
else:
|
| 304 |
+
print("β οΈ post_install.py not found, attempting manual installation...")
|
| 305 |
+
|
| 306 |
+
# Manual installation of critical dependencies
|
| 307 |
+
try:
|
| 308 |
+
print("π¦ Installing nvdiffrast...")
|
| 309 |
+
result = subprocess.run([sys.executable, "-m", "pip", "install", "nvdiffrast"],
|
| 310 |
+
capture_output=True, text=True, timeout=300)
|
| 311 |
+
if result.returncode == 0:
|
| 312 |
+
print("β
nvdiffrast installed successfully")
|
| 313 |
+
else:
|
| 314 |
+
print(f"β οΈ nvdiffrast installation failed: {result.stderr}")
|
| 315 |
+
|
| 316 |
+
print("π¦ Installing pytorch3d...")
|
| 317 |
+
result = subprocess.run([sys.executable, "-m", "pip", "install", "pytorch3d", "--no-deps"],
|
| 318 |
+
capture_output=True, text=True, timeout=300)
|
| 319 |
+
if result.returncode == 0:
|
| 320 |
+
print("β
pytorch3d installed successfully")
|
| 321 |
+
else:
|
| 322 |
+
print(f"β οΈ pytorch3d installation failed: {result.stderr}")
|
| 323 |
+
|
| 324 |
+
print("π¦ Installing FashionCLIP...")
|
| 325 |
+
if os.path.exists("packages/fashion_clip"):
|
| 326 |
+
result = subprocess.run([sys.executable, "-m", "pip", "install", "-e", "packages/fashion_clip"],
|
| 327 |
+
capture_output=True, text=True, timeout=300)
|
| 328 |
+
if result.returncode == 0:
|
| 329 |
+
print("β
FashionCLIP installed successfully")
|
| 330 |
+
else:
|
| 331 |
+
print(f"β οΈ FashionCLIP installation failed: {result.stderr}")
|
| 332 |
+
else:
|
| 333 |
+
print("β οΈ FashionCLIP directory not found")
|
| 334 |
+
|
| 335 |
+
print("β
Manual installation completed")
|
| 336 |
+
|
| 337 |
+
# Re-check dependencies after installation
|
| 338 |
+
print("π Re-checking dependencies after installation...")
|
| 339 |
+
try:
|
| 340 |
+
import nvdiffrast
|
| 341 |
+
print("β
nvdiffrast now available")
|
| 342 |
+
except ImportError:
|
| 343 |
+
print("β οΈ nvdiffrast still not available")
|
| 344 |
+
|
| 345 |
+
try:
|
| 346 |
+
import pytorch3d
|
| 347 |
+
print("β
pytorch3d now available")
|
| 348 |
+
except ImportError:
|
| 349 |
+
print("β οΈ pytorch3d still not available")
|
| 350 |
+
|
| 351 |
+
try:
|
| 352 |
+
from packages.fashion_clip.fashion_clip.fashion_clip import FashionCLIP
|
| 353 |
+
print("β
FashionCLIP now available")
|
| 354 |
+
except ImportError:
|
| 355 |
+
print("β οΈ FashionCLIP still not available")
|
| 356 |
+
|
| 357 |
+
except Exception as e:
|
| 358 |
+
print(f"β οΈ Manual installation failed: {e}")
|
| 359 |
+
|
| 360 |
except Exception as e:
|
| 361 |
print(f"β οΈ Could not run post-install script: {e}")
|
| 362 |
else:
|
|
|
|
| 364 |
|
| 365 |
except Exception as e:
|
| 366 |
print(f"β οΈ Error checking dependencies: {e}")
|
| 367 |
+
else:
|
| 368 |
+
print("π Local development environment detected")
|
| 369 |
|
| 370 |
+
# Try to import the loop module after dependency installation attempts
|
| 371 |
+
print("π Attempting to import processing engine after dependency checks...")
|
| 372 |
import_success = try_import_loop()
|
| 373 |
|
| 374 |
if import_success:
|
|
|
|
| 385 |
print(" - All other required packages")
|
| 386 |
|
| 387 |
# In production, we should fail fast if critical dependencies are missing
|
| 388 |
+
if is_hf_spaces:
|
| 389 |
print("π¨ Production environment detected - exiting due to missing dependencies")
|
| 390 |
print("π‘ Try running: python post_install.py")
|
| 391 |
+
print("π‘ Or check the logs above for installation errors")
|
| 392 |
+
print("π‘ You may need to restart the application after dependencies are installed")
|
| 393 |
sys.exit(1)
|
| 394 |
else:
|
| 395 |
print("β οΈ Development mode - continuing with limited functionality")
|