Update app.py
Browse files
app.py
CHANGED
|
@@ -15,15 +15,22 @@ from accelerate.utils import set_seed
|
|
| 15 |
from latentsync.whisper.audio2feature import Audio2Feature
|
| 16 |
from openai import OpenAI
|
| 17 |
from elevenlabs import set_api_key, generate, play, clone, Voice, VoiceSettings
|
|
|
|
| 18 |
|
| 19 |
# Initialize the Flask app
|
| 20 |
app = Flask(__name__)
|
| 21 |
TEMP_DIR = None
|
| 22 |
VIDEO_DIRECTORY = None
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def run_inference(video_path, audio_path, video_out_path,
|
| 25 |
inference_ckpt_path, unet_config_path="configs/unet/second_stage.yaml",
|
| 26 |
inference_steps=20, guidance_scale=1.0, seed=1247):
|
|
|
|
|
|
|
| 27 |
# Load configuration
|
| 28 |
config = OmegaConf.load(unet_config_path)
|
| 29 |
|
|
@@ -77,19 +84,22 @@ def run_inference(video_path, audio_path, video_out_path,
|
|
| 77 |
else:
|
| 78 |
torch.seed()
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
def create_temp_dir():
|
| 95 |
return tempfile.TemporaryDirectory()
|
|
|
|
| 15 |
from latentsync.whisper.audio2feature import Audio2Feature
|
| 16 |
from openai import OpenAI
|
| 17 |
from elevenlabs import set_api_key, generate, play, clone, Voice, VoiceSettings
|
| 18 |
+
from torch.cuda.amp import autocast
|
| 19 |
|
| 20 |
# Initialize the Flask app
|
| 21 |
app = Flask(__name__)
|
| 22 |
TEMP_DIR = None
|
| 23 |
VIDEO_DIRECTORY = None
|
| 24 |
|
| 25 |
+
def clear_cuda_memory():
|
| 26 |
+
torch.cuda.empty_cache()
|
| 27 |
+
gc.collect(
|
| 28 |
+
|
| 29 |
def run_inference(video_path, audio_path, video_out_path,
|
| 30 |
inference_ckpt_path, unet_config_path="configs/unet/second_stage.yaml",
|
| 31 |
inference_steps=20, guidance_scale=1.0, seed=1247):
|
| 32 |
+
clear_cuda_memory()
|
| 33 |
+
|
| 34 |
# Load configuration
|
| 35 |
config = OmegaConf.load(unet_config_path)
|
| 36 |
|
|
|
|
| 84 |
else:
|
| 85 |
torch.seed()
|
| 86 |
|
| 87 |
+
with autocast():
|
| 88 |
+
try:
|
| 89 |
+
pipeline(
|
| 90 |
+
video_path=video_path,
|
| 91 |
+
audio_path=audio_path,
|
| 92 |
+
video_out_path=video_out_path,
|
| 93 |
+
video_mask_path=video_out_path.replace(".mp4", "_mask.mp4"),
|
| 94 |
+
num_frames=config.data.num_frames,
|
| 95 |
+
num_inference_steps=inference_steps,
|
| 96 |
+
guidance_scale=guidance_scale,
|
| 97 |
+
weight_dtype=dtype,
|
| 98 |
+
width=config.data.resolution,
|
| 99 |
+
height=config.data.resolution,
|
| 100 |
+
)
|
| 101 |
+
finally:
|
| 102 |
+
clear_cuda_memory()
|
| 103 |
|
| 104 |
def create_temp_dir():
|
| 105 |
return tempfile.TemporaryDirectory()
|