Update app_enhanced.py
Browse files- app_enhanced.py +20 -10
app_enhanced.py
CHANGED
|
@@ -11,21 +11,23 @@ import random
|
|
| 11 |
from concurrent.futures import ThreadPoolExecutor
|
| 12 |
from flask import Flask, render_template, request, jsonify, send_from_directory, send_file
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
#
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
# This global function ensures the ZeroGPU scanner knows we need GPU resources.
|
| 20 |
@spaces.GPU
|
| 21 |
def zero_gpu_warmup():
|
| 22 |
-
print("ZeroGPU
|
| 23 |
|
| 24 |
-
#
|
|
|
|
|
|
|
| 25 |
logging.basicConfig(level=logging.INFO)
|
| 26 |
logger = logging.getLogger(__name__)
|
| 27 |
|
| 28 |
-
# ---
|
| 29 |
try:
|
| 30 |
import cv2
|
| 31 |
import numpy as np
|
|
@@ -38,7 +40,7 @@ except ImportError as e:
|
|
| 38 |
Image = None
|
| 39 |
srt = None
|
| 40 |
|
| 41 |
-
# ---
|
| 42 |
def dummy_func(*args, **kwargs):
|
| 43 |
return 0, 0, None, None
|
| 44 |
|
|
@@ -752,7 +754,9 @@ class EnhancedComicGenerator:
|
|
| 752 |
|
| 753 |
return pages
|
| 754 |
|
| 755 |
-
#
|
|
|
|
|
|
|
| 756 |
@spaces.GPU(duration=300)
|
| 757 |
def generate_comic(self):
|
| 758 |
start_time = time.time()
|
|
@@ -844,6 +848,9 @@ class EnhancedComicGenerator:
|
|
| 844 |
except Exception as e:
|
| 845 |
print(f"β Save results failed: {e}")
|
| 846 |
|
|
|
|
|
|
|
|
|
|
| 847 |
@spaces.GPU
|
| 848 |
def regenerate_frame(self, fname, direction):
|
| 849 |
try:
|
|
@@ -900,6 +907,9 @@ class EnhancedComicGenerator:
|
|
| 900 |
traceback.print_exc()
|
| 901 |
return {"success": False, "message": str(e)}
|
| 902 |
|
|
|
|
|
|
|
|
|
|
| 903 |
@spaces.GPU
|
| 904 |
def get_frame_at_timestamp(self, fname, ts):
|
| 905 |
try:
|
|
|
|
| 11 |
from concurrent.futures import ThreadPoolExecutor
|
| 12 |
from flask import Flask, render_template, request, jsonify, send_from_directory, send_file
|
| 13 |
|
| 14 |
+
# ==========================================
|
| 15 |
+
# π ZEROGPU CRITICAL SETUP
|
| 16 |
+
# ==========================================
|
| 17 |
+
import spaces # Must be imported at module level
|
| 18 |
|
| 19 |
+
# This dummy function guarantees HF detects the GPU requirement
|
|
|
|
| 20 |
@spaces.GPU
|
| 21 |
def zero_gpu_warmup():
|
| 22 |
+
print("β
ZeroGPU Active")
|
| 23 |
|
| 24 |
+
# ==========================================
|
| 25 |
+
# βοΈ CONFIG & DEPENDENCIES
|
| 26 |
+
# ==========================================
|
| 27 |
logging.basicConfig(level=logging.INFO)
|
| 28 |
logger = logging.getLogger(__name__)
|
| 29 |
|
| 30 |
+
# --- Core Libraries ---
|
| 31 |
try:
|
| 32 |
import cv2
|
| 33 |
import numpy as np
|
|
|
|
| 40 |
Image = None
|
| 41 |
srt = None
|
| 42 |
|
| 43 |
+
# --- Backend Imports with Fallbacks ---
|
| 44 |
def dummy_func(*args, **kwargs):
|
| 45 |
return 0, 0, None, None
|
| 46 |
|
|
|
|
| 754 |
|
| 755 |
return pages
|
| 756 |
|
| 757 |
+
# ==========================================
|
| 758 |
+
# π ZEROGPU DECORATED FUNCTION
|
| 759 |
+
# ==========================================
|
| 760 |
@spaces.GPU(duration=300)
|
| 761 |
def generate_comic(self):
|
| 762 |
start_time = time.time()
|
|
|
|
| 848 |
except Exception as e:
|
| 849 |
print(f"β Save results failed: {e}")
|
| 850 |
|
| 851 |
+
# ==========================================
|
| 852 |
+
# π ZEROGPU DECORATED FUNCTION
|
| 853 |
+
# ==========================================
|
| 854 |
@spaces.GPU
|
| 855 |
def regenerate_frame(self, fname, direction):
|
| 856 |
try:
|
|
|
|
| 907 |
traceback.print_exc()
|
| 908 |
return {"success": False, "message": str(e)}
|
| 909 |
|
| 910 |
+
# ==========================================
|
| 911 |
+
# π ZEROGPU DECORATED FUNCTION
|
| 912 |
+
# ==========================================
|
| 913 |
@spaces.GPU
|
| 914 |
def get_frame_at_timestamp(self, fname, ts):
|
| 915 |
try:
|