Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""
|
| 2 |
Face Swapper HD Professional - Optimized for Hugging Face Spaces
|
| 3 |
Author: AI Assistant
|
| 4 |
-
Version: 2.
|
| 5 |
License: MIT
|
| 6 |
"""
|
| 7 |
|
|
@@ -14,20 +14,27 @@ from contextlib import contextmanager
|
|
| 14 |
from dataclasses import dataclass
|
| 15 |
from enum import Enum
|
| 16 |
from typing import Optional, Tuple, List, Any, Dict, Generator
|
|
|
|
| 17 |
|
| 18 |
-
# --- PARCHE DE COMPATIBILIDAD PARA TORCHVISION ---
|
| 19 |
-
#
|
| 20 |
try:
|
| 21 |
-
import torchvision
|
| 22 |
import torchvision.transforms.functional as F
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
import cv2
|
| 33 |
import gradio as gr
|
|
|
|
| 1 |
"""
|
| 2 |
Face Swapper HD Professional - Optimized for Hugging Face Spaces
|
| 3 |
Author: AI Assistant
|
| 4 |
+
Version: 2.2.0
|
| 5 |
License: MIT
|
| 6 |
"""
|
| 7 |
|
|
|
|
| 14 |
from dataclasses import dataclass
|
| 15 |
from enum import Enum
|
| 16 |
from typing import Optional, Tuple, List, Any, Dict, Generator
|
| 17 |
+
from types import ModuleType
|
| 18 |
|
| 19 |
+
# --- PARCHE DE COMPATIBILIDAD TOTAL PARA TORCHVISION (Versión 2026) ---
|
| 20 |
+
# Este bloque debe ejecutarse antes que cualquier importación de IA
|
| 21 |
try:
|
|
|
|
| 22 |
import torchvision.transforms.functional as F
|
| 23 |
+
# Creamos el módulo fantasma que las librerías antiguas (GFPGAN/facexlib) buscan
|
| 24 |
+
mock_ft = ModuleType("torchvision.transforms.functional_tensor")
|
| 25 |
+
|
| 26 |
+
# Inyectamos las funciones críticas para procesamiento profesional
|
| 27 |
+
mock_ft.rgb_to_grayscale = F.rgb_to_grayscale
|
| 28 |
+
mock_ft.to_tensor = F.to_tensor
|
| 29 |
+
mock_ft.normalize = F.normalize
|
| 30 |
+
mock_ft.convert_image_dtype = F.convert_image_dtype
|
| 31 |
+
|
| 32 |
+
# Lo registramos globalmente en el sistema
|
| 33 |
+
sys.modules["torchvision.transforms.functional_tensor"] = mock_ft
|
| 34 |
+
print("✅ Parche de compatibilidad Vision aplicado exitosamente.")
|
| 35 |
+
except Exception as e:
|
| 36 |
+
print(f"⚠️ Aviso: No se pudo aplicar el parche: {e}")
|
| 37 |
+
# -----------------------------------------------------------------------
|
| 38 |
|
| 39 |
import cv2
|
| 40 |
import gradio as gr
|