Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import gradio as gr
|
|
| 4 |
import AnimeGANv3_src
|
| 5 |
import numpy as np
|
| 6 |
import logging
|
|
|
|
| 7 |
|
| 8 |
# Set up logging
|
| 9 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
@@ -13,6 +14,10 @@ class AnimeGANv3:
|
|
| 13 |
os.makedirs('output', exist_ok=True)
|
| 14 |
os.makedirs('frames', exist_ok=True)
|
| 15 |
logging.info(f"Available ONNX Runtime providers: {ort.get_available_providers()}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def process_frame(self, frame, style_code, det_face):
|
| 18 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
@@ -45,12 +50,12 @@ class AnimeGANv3:
|
|
| 45 |
logging.info(f"Extracted {frame_count} frames at {fps} FPS to process")
|
| 46 |
|
| 47 |
# Process in batches
|
| 48 |
-
batch_size = 50 # Adjust based on testing
|
| 49 |
save_path = "output/out.mp4"
|
| 50 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 51 |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 52 |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 53 |
-
out = None
|
| 54 |
|
| 55 |
frame_idx = 0
|
| 56 |
while cap.isOpened():
|
|
@@ -65,7 +70,6 @@ class AnimeGANv3:
|
|
| 65 |
if not batch_frames:
|
| 66 |
break
|
| 67 |
|
| 68 |
-
# Process batch
|
| 69 |
for idx, frame in enumerate(batch_frames):
|
| 70 |
stylized_frame = self.process_frame(frame, style_code, det_face)
|
| 71 |
if out is None: # Initialize writer on first frame
|
|
|
|
| 4 |
import AnimeGANv3_src
|
| 5 |
import numpy as np
|
| 6 |
import logging
|
| 7 |
+
import onnxruntime as ort # Added this import
|
| 8 |
|
| 9 |
# Set up logging
|
| 10 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
| 14 |
os.makedirs('output', exist_ok=True)
|
| 15 |
os.makedirs('frames', exist_ok=True)
|
| 16 |
logging.info(f"Available ONNX Runtime providers: {ort.get_available_providers()}")
|
| 17 |
+
if 'CUDAExecutionProvider' in ort.get_available_providers():
|
| 18 |
+
logging.info("Running on GPU with CUDA")
|
| 19 |
+
else:
|
| 20 |
+
logging.info("Running on CPU")
|
| 21 |
|
| 22 |
def process_frame(self, frame, style_code, det_face):
|
| 23 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
|
|
| 50 |
logging.info(f"Extracted {frame_count} frames at {fps} FPS to process")
|
| 51 |
|
| 52 |
# Process in batches
|
| 53 |
+
batch_size = 50 # Adjust based on testing
|
| 54 |
save_path = "output/out.mp4"
|
| 55 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 56 |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 57 |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 58 |
+
out = None
|
| 59 |
|
| 60 |
frame_idx = 0
|
| 61 |
while cap.isOpened():
|
|
|
|
| 70 |
if not batch_frames:
|
| 71 |
break
|
| 72 |
|
|
|
|
| 73 |
for idx, frame in enumerate(batch_frames):
|
| 74 |
stylized_frame = self.process_frame(frame, style_code, det_face)
|
| 75 |
if out is None: # Initialize writer on first frame
|