Ali Mohsin commited on
Commit
fd9f634
Β·
1 Parent(s): 8d61874

more fixes

Browse files
Files changed (1) hide show
  1. app.py +81 -7
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
- if os.environ.get('HUGGING_FACE_SPACES', '0') == '1':
 
 
 
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
- result = subprocess.run([sys.executable, "post_install.py"],
287
- capture_output=True, text=True, timeout=300)
288
- if result.returncode == 0:
289
- print("βœ… Post-install script completed successfully")
 
 
 
 
 
 
 
 
 
 
290
  else:
291
- print(f"⚠️ Post-install script failed: {result.stderr}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 os.environ.get('HUGGING_FACE_SPACES', '0') == '1':
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")