Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import cv2
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
|
@@ -11,25 +16,63 @@ from reportlab.pdfgen import canvas
|
|
| 11 |
from reportlab.lib.units import inch
|
| 12 |
from io import BytesIO
|
| 13 |
import base64
|
| 14 |
-
import logging
|
| 15 |
from retrying import retry
|
| 16 |
import uuid
|
| 17 |
from multiprocessing import Pool, cpu_count
|
| 18 |
from functools import partial
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# ==========================
|
| 23 |
# ByteTrack Installation & Import
|
| 24 |
# ==========================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
from bytetrack import BYTETracker
|
|
|
|
| 27 |
except ImportError:
|
| 28 |
-
logger
|
| 29 |
-
|
| 30 |
-
subprocess.
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# ==========================
|
| 35 |
# Optimized Configuration
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
+
import subprocess
|
| 4 |
+
import logging
|
| 5 |
+
import warnings
|
| 6 |
+
from importlib import import_module
|
| 7 |
import cv2
|
| 8 |
import gradio as gr
|
| 9 |
import torch
|
|
|
|
| 16 |
from reportlab.lib.units import inch
|
| 17 |
from io import BytesIO
|
| 18 |
import base64
|
|
|
|
| 19 |
from retrying import retry
|
| 20 |
import uuid
|
| 21 |
from multiprocessing import Pool, cpu_count
|
| 22 |
from functools import partial
|
| 23 |
+
|
| 24 |
+
# Handle Ultralytics config directory warning
|
| 25 |
+
os.environ['YOLO_CONFIG_DIR'] = '/tmp/Ultralytics'
|
| 26 |
+
os.makedirs('/tmp/Ultralytics', exist_ok=True)
|
| 27 |
|
| 28 |
# ==========================
|
| 29 |
# ByteTrack Installation & Import
|
| 30 |
# ==========================
|
| 31 |
+
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
| 32 |
+
|
| 33 |
+
# Setup logging before using it
|
| 34 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 35 |
+
logger = logging.getLogger(__name__)
|
| 36 |
+
|
| 37 |
try:
|
| 38 |
from bytetrack import BYTETracker
|
| 39 |
+
logger.info("ByteTrack successfully imported")
|
| 40 |
except ImportError:
|
| 41 |
+
logger.warning("ByteTrack not found, installing dependencies...")
|
| 42 |
+
|
| 43 |
+
subprocess.run(
|
| 44 |
+
[sys.executable, "-m", "pip", "install", "-q", "cython", "lap", "numpy"],
|
| 45 |
+
check=True
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
subprocess.run(
|
| 49 |
+
[sys.executable, "-m", "pip", "install", "-q", "git+https://github.com/ifzhang/ByteTrack.git@main"],
|
| 50 |
+
check=True
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
for module in list(sys.modules.keys()):
|
| 54 |
+
if module.startswith('bytetrack') or module.startswith('yolox'):
|
| 55 |
+
del sys.modules[module]
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
from bytetrack import BYTETracker
|
| 59 |
+
logger.info("ByteTrack successfully installed and imported")
|
| 60 |
+
except ImportError as e:
|
| 61 |
+
logger.error(f"Failed to install/import ByteTrack: {e}")
|
| 62 |
+
raise RuntimeError("Could not initialize ByteTrack tracker") from e
|
| 63 |
+
|
| 64 |
+
warnings.filterwarnings("default")
|
| 65 |
+
# ==========================
|
| 66 |
+
# ByteTrack Installation & Import
|
| 67 |
+
# ==========================
|
| 68 |
+
#try:
|
| 69 |
+
# from bytetrack import BYTETracker
|
| 70 |
+
#except ImportError:
|
| 71 |
+
# logger = logging.getLogger(__name__)
|
| 72 |
+
# logger.warning("ByteTrack not found, installing...")
|
| 73 |
+
# subprocess.check_call([sys.executable, "-m", "pip", "install", "cython", "lap"])
|
| 74 |
+
# subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/ifzhang/ByteTrack.git@main"])
|
| 75 |
+
# from bytetrack import BYTETracker
|
| 76 |
|
| 77 |
# ==========================
|
| 78 |
# Optimized Configuration
|