Spaces:
Runtime error
Runtime error
Commit
·
9e3a8fe
1
Parent(s):
230092e
V1.1
Browse files
app.py
CHANGED
|
@@ -17,6 +17,21 @@ import sys
|
|
| 17 |
import time
|
| 18 |
import numpy as np
|
| 19 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Status flags for optional dependencies
|
| 22 |
CV2_AVAILABLE = False
|
|
@@ -28,41 +43,7 @@ MODELS_IMPORTED = False
|
|
| 28 |
if not os.getcwd() in sys.path:
|
| 29 |
sys.path.append(os.getcwd())
|
| 30 |
|
| 31 |
-
# OpenCV import - wrapped in try-except to make it optional
|
| 32 |
-
try:
|
| 33 |
-
import cv2
|
| 34 |
-
CV2_AVAILABLE = True
|
| 35 |
-
except ImportError:
|
| 36 |
-
print("Warning: OpenCV (cv2) is not installed. Using demo mode.")
|
| 37 |
-
|
| 38 |
-
# PyTorch imports - wrapped in try-except to make them optional
|
| 39 |
-
try:
|
| 40 |
-
import torch
|
| 41 |
-
from torchvision import transforms
|
| 42 |
-
from PIL import Image
|
| 43 |
-
TORCH_AVAILABLE = True
|
| 44 |
-
except ImportError:
|
| 45 |
-
print("Warning: PyTorch or related libraries are not installed. Using demo mode.")
|
| 46 |
-
|
| 47 |
-
# Detectron2 imports - wrapped in try-except to make them optional
|
| 48 |
-
if TORCH_AVAILABLE and CV2_AVAILABLE:
|
| 49 |
-
try:
|
| 50 |
-
from detectron2.engine import DefaultPredictor
|
| 51 |
-
from detectron2.config import get_cfg
|
| 52 |
-
from detectron2.utils.visualizer import Visualizer, ColorMode
|
| 53 |
-
from detectron2 import model_zoo
|
| 54 |
-
DETECTRON2_AVAILABLE = True
|
| 55 |
-
except ImportError:
|
| 56 |
-
print("Warning: Detectron2 is not installed. Damage detection will not be available.")
|
| 57 |
|
| 58 |
-
# Check for custom path for models if all required dependencies are available
|
| 59 |
-
if TORCH_AVAILABLE and CV2_AVAILABLE:
|
| 60 |
-
try:
|
| 61 |
-
from configs.get_config import load_config
|
| 62 |
-
from models import *
|
| 63 |
-
MODELS_IMPORTED = True
|
| 64 |
-
except ImportError:
|
| 65 |
-
print("Warning: Custom models couldn't be imported. Only damage detection will work if available.")
|
| 66 |
|
| 67 |
def check_model_files(damage_model_path, deepfake_model_path, deepfake_cfg_path):
|
| 68 |
"""Check if required model files exist and return status"""
|
|
|
|
| 17 |
import time
|
| 18 |
import numpy as np
|
| 19 |
import gradio as gr
|
| 20 |
+
# OpenCV import - wrapped in try-except to make it optional
|
| 21 |
+
import cv2
|
| 22 |
+
|
| 23 |
+
from torchvision import transforms
|
| 24 |
+
from PIL import Image
|
| 25 |
+
# Detectron2 imports - wrapped in try-except to make them optional
|
| 26 |
+
|
| 27 |
+
from detectron2.engine import DefaultPredictor
|
| 28 |
+
from detectron2.config import get_cfg
|
| 29 |
+
from detectron2.utils.visualizer import Visualizer, ColorMode
|
| 30 |
+
from detectron2 import model_zoo
|
| 31 |
+
|
| 32 |
+
from configs.get_config import load_config
|
| 33 |
+
from models import *
|
| 34 |
+
|
| 35 |
|
| 36 |
# Status flags for optional dependencies
|
| 37 |
CV2_AVAILABLE = False
|
|
|
|
| 43 |
if not os.getcwd() in sys.path:
|
| 44 |
sys.path.append(os.getcwd())
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def check_model_files(damage_model_path, deepfake_model_path, deepfake_cfg_path):
|
| 49 |
"""Check if required model files exist and return status"""
|