Update app_enhanced.py
Browse files- app_enhanced.py +16 -8
app_enhanced.py
CHANGED
|
@@ -13,7 +13,6 @@ from flask import Flask, jsonify, request, send_from_directory, send_file
|
|
| 13 |
# ======================================================
|
| 14 |
# 🚀 ZEROGPU DETECTION FUNCTION
|
| 15 |
# ======================================================
|
| 16 |
-
# This function exists solely to be detected by Hugging Face
|
| 17 |
@spaces.GPU
|
| 18 |
def gpu_warmup():
|
| 19 |
import torch
|
|
@@ -80,8 +79,8 @@ def generate_comic_gpu(video_path, user_dir, frames_dir, metadata_path):
|
|
| 80 |
cap = cv2.VideoCapture(video_path)
|
| 81 |
count = 0
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
for i, moment in enumerate(key_moments[:
|
| 85 |
mid_time = (moment['start'] + moment['end']) / 2
|
| 86 |
if mid_time > duration: continue
|
| 87 |
|
|
@@ -105,12 +104,18 @@ def generate_comic_gpu(video_path, user_dir, frames_dir, metadata_path):
|
|
| 105 |
qe = QualityColorEnhancer()
|
| 106 |
frame_files = sorted([f for f in os.listdir(frames_dir) if f.endswith('.png')])
|
| 107 |
|
|
|
|
| 108 |
for f in frame_files:
|
| 109 |
p = os.path.join(frames_dir, f)
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
# 5. Bubbles
|
|
|
|
| 114 |
bubbles_list = []
|
| 115 |
for f in frame_files:
|
| 116 |
p = os.path.join(frames_dir, f)
|
|
@@ -124,6 +129,7 @@ def generate_comic_gpu(video_path, user_dir, frames_dir, metadata_path):
|
|
| 124 |
bubbles_list.append(bubble(dialog=dialogue))
|
| 125 |
|
| 126 |
# 6. Layout
|
|
|
|
| 127 |
try:
|
| 128 |
from backend.fixed_12_pages_800x1080 import generate_12_pages_800x1080
|
| 129 |
pages = generate_12_pages_800x1080(frame_files, bubbles_list)
|
|
@@ -148,6 +154,8 @@ def generate_comic_gpu(video_path, user_dir, frames_dir, metadata_path):
|
|
| 148 |
def regen_frame_gpu(video_path, frames_dir, metadata_path, fname, direction):
|
| 149 |
import cv2
|
| 150 |
import json
|
|
|
|
|
|
|
| 151 |
if not os.path.exists(metadata_path): return None
|
| 152 |
with open(metadata_path, 'r') as f: meta = json.load(f)
|
| 153 |
if fname not in meta: return None
|
|
@@ -165,9 +173,9 @@ def regen_frame_gpu(video_path, frames_dir, metadata_path, fname, direction):
|
|
| 165 |
if ret:
|
| 166 |
path = os.path.join(frames_dir, fname)
|
| 167 |
cv2.imwrite(path, frame)
|
| 168 |
-
#
|
| 169 |
-
|
| 170 |
-
|
| 171 |
|
| 172 |
if isinstance(meta[fname], dict): meta[fname]['time'] = new_t
|
| 173 |
else: meta[fname] = new_t
|
|
|
|
| 13 |
# ======================================================
|
| 14 |
# 🚀 ZEROGPU DETECTION FUNCTION
|
| 15 |
# ======================================================
|
|
|
|
| 16 |
@spaces.GPU
|
| 17 |
def gpu_warmup():
|
| 18 |
import torch
|
|
|
|
| 79 |
cap = cv2.VideoCapture(video_path)
|
| 80 |
count = 0
|
| 81 |
|
| 82 |
+
# Process frames
|
| 83 |
+
for i, moment in enumerate(key_moments[:32]): # Limit frames for stability
|
| 84 |
mid_time = (moment['start'] + moment['end']) / 2
|
| 85 |
if mid_time > duration: continue
|
| 86 |
|
|
|
|
| 104 |
qe = QualityColorEnhancer()
|
| 105 |
frame_files = sorted([f for f in os.listdir(frames_dir) if f.endswith('.png')])
|
| 106 |
|
| 107 |
+
print(f"🎨 Enhancing {len(frame_files)} frames...")
|
| 108 |
for f in frame_files:
|
| 109 |
p = os.path.join(frames_dir, f)
|
| 110 |
+
# FIX: Pass 'p' as both input and output path to overwrite
|
| 111 |
+
try: se.enhance_single(p, p)
|
| 112 |
+
except Exception as e: print(f"SimpleEnhance error on {f}: {e}")
|
| 113 |
+
|
| 114 |
+
try: qe.enhance_single(p, p)
|
| 115 |
+
except Exception as e: print(f"QualityEnhance error on {f}: {e}")
|
| 116 |
|
| 117 |
# 5. Bubbles
|
| 118 |
+
print("💬 Placing bubbles...")
|
| 119 |
bubbles_list = []
|
| 120 |
for f in frame_files:
|
| 121 |
p = os.path.join(frames_dir, f)
|
|
|
|
| 129 |
bubbles_list.append(bubble(dialog=dialogue))
|
| 130 |
|
| 131 |
# 6. Layout
|
| 132 |
+
print("📄 Generating layout...")
|
| 133 |
try:
|
| 134 |
from backend.fixed_12_pages_800x1080 import generate_12_pages_800x1080
|
| 135 |
pages = generate_12_pages_800x1080(frame_files, bubbles_list)
|
|
|
|
| 154 |
def regen_frame_gpu(video_path, frames_dir, metadata_path, fname, direction):
|
| 155 |
import cv2
|
| 156 |
import json
|
| 157 |
+
from backend.simple_color_enhancer import SimpleColorEnhancer
|
| 158 |
+
|
| 159 |
if not os.path.exists(metadata_path): return None
|
| 160 |
with open(metadata_path, 'r') as f: meta = json.load(f)
|
| 161 |
if fname not in meta: return None
|
|
|
|
| 173 |
if ret:
|
| 174 |
path = os.path.join(frames_dir, fname)
|
| 175 |
cv2.imwrite(path, frame)
|
| 176 |
+
# FIX: Pass output path
|
| 177 |
+
try: SimpleColorEnhancer().enhance_single(path, path)
|
| 178 |
+
except: pass
|
| 179 |
|
| 180 |
if isinstance(meta[fname], dict): meta[fname]['time'] = new_t
|
| 181 |
else: meta[fname] = new_t
|