Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
try:
|
| 449 |
-
|
| 450 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
except Exception as e:
|
| 452 |
-
log_message(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 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 []
|