Malaji71 commited on
Commit
b45cab7
Β·
verified Β·
1 Parent(s): e2a93e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -6
app.py CHANGED
@@ -443,13 +443,41 @@ def upscale_video_4k(input_path, output_path):
443
  # Initialize directories and try to set up Real-ESRGAN
444
  ensure_directories()
445
 
446
- # Try to initialize Real-ESRGAN on startup
447
- if REALESRGAN_AVAILABLE:
 
 
 
 
 
 
448
  try:
449
- log_message("πŸš€ Attempting to initialize Real-ESRGAN on startup...")
450
- initialize_realesrgan()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  except Exception as e:
452
- log_message(f"⚠️ Could not initialize Real-ESRGAN on startup: {e}")
 
 
 
 
 
 
 
453
 
454
  app = Flask(__name__)
455
 
@@ -484,9 +512,19 @@ def api_system():
484
  info["pytorch_version"] = torch.__version__
485
 
486
  # Real-ESRGAN info
487
- info["realesrgan_available"] = REALESRGAN_AVAILABLE and app_state["upscaler"] is not None
 
488
  info["current_model"] = app_state.get("current_model", "None")
489
 
 
 
 
 
 
 
 
 
 
490
  # Storage info
491
  try:
492
  upload_files = os.listdir(UPLOAD_FOLDER) if os.path.exists(UPLOAD_FOLDER) else []
 
443
  # Initialize directories and try to set up Real-ESRGAN
444
  ensure_directories()
445
 
446
+ def force_init_realesrgan():
447
+ """Force Real-ESRGAN initialization with detailed logging"""
448
+ log_message("πŸ”§ Force initializing Real-ESRGAN...")
449
+
450
+ if not REALESRGAN_AVAILABLE:
451
+ log_message("❌ Real-ESRGAN package not available")
452
+ return False
453
+
454
  try:
455
+ # Try to download models first
456
+ log_message("πŸ“₯ Checking/downloading Real-ESRGAN models...")
457
+ download_success = download_realesrgan_models()
458
+ if not download_success:
459
+ log_message("❌ Model download failed")
460
+ return False
461
+
462
+ # Initialize upscaler
463
+ log_message("πŸ”§ Creating Real-ESRGAN upscaler...")
464
+ upscaler = initialize_realesrgan()
465
+ if upscaler:
466
+ log_message("βœ… Real-ESRGAN initialized successfully!")
467
+ return True
468
+ else:
469
+ log_message("❌ Real-ESRGAN initialization returned None")
470
+ return False
471
+
472
  except Exception as e:
473
+ log_message(f"❌ Real-ESRGAN initialization error: {str(e)}")
474
+ import traceback
475
+ log_message(f"πŸ” Traceback: {traceback.format_exc()}")
476
+ return False
477
+
478
+ # Try to initialize Real-ESRGAN on startup
479
+ log_message("πŸš€ Starting Real-ESRGAN initialization...")
480
+ force_init_realesrgan()
481
 
482
  app = Flask(__name__)
483
 
 
512
  info["pytorch_version"] = torch.__version__
513
 
514
  # Real-ESRGAN info
515
+ info["realesrgan_available"] = REALESRGAN_AVAILABLE
516
+ info["realesrgan_initialized"] = app_state["upscaler"] is not None
517
  info["current_model"] = app_state.get("current_model", "None")
518
 
519
+ # Check if models exist
520
+ models_status = {}
521
+ if REALESRGAN_AVAILABLE:
522
+ models = ['RealESRGAN_x4plus', 'RealESRGAN_x2plus']
523
+ for model in models:
524
+ model_path = os.path.join(MODEL_FOLDER, f"{model}.pth")
525
+ models_status[model] = os.path.exists(model_path)
526
+ info["models_downloaded"] = models_status
527
+
528
  # Storage info
529
  try:
530
  upload_files = os.listdir(UPLOAD_FOLDER) if os.path.exists(UPLOAD_FOLDER) else []