Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
-
import torch
|
| 6 |
from PIL import Image
|
| 7 |
|
| 8 |
from composer import compose_frames, crop_reserved_region
|
|
@@ -22,8 +22,6 @@ _pipeline_state = None
|
|
| 22 |
|
| 23 |
|
| 24 |
def make_temp_file(suffix: str) -> str:
|
| 25 |
-
import tempfile
|
| 26 |
-
|
| 27 |
fd, path = tempfile.mkstemp(suffix=suffix)
|
| 28 |
os.close(fd)
|
| 29 |
return path
|
|
@@ -102,4 +100,22 @@ def generate(
|
|
| 102 |
cropped = crop_reserved_region(
|
| 103 |
generated,
|
| 104 |
region_position="left",
|
| 105 |
-
region_size_px=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import tempfile
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
from PIL import Image
|
| 7 |
|
| 8 |
from composer import compose_frames, crop_reserved_region
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def make_temp_file(suffix: str) -> str:
|
|
|
|
|
|
|
| 25 |
fd, path = tempfile.mkstemp(suffix=suffix)
|
| 26 |
os.close(fd)
|
| 27 |
return path
|
|
|
|
| 100 |
cropped = crop_reserved_region(
|
| 101 |
generated,
|
| 102 |
region_position="left",
|
| 103 |
+
region_size_px=REGION_SIZE,
|
| 104 |
+
output_size=(target_w, target_h),
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
progress(0.95, desc="Encoding output video…")
|
| 108 |
+
out_path = make_temp_file(".mp4")
|
| 109 |
+
save_video(
|
| 110 |
+
cropped,
|
| 111 |
+
fps=fps,
|
| 112 |
+
output_path=out_path,
|
| 113 |
+
audio_path=audio_tmp if has_audio else None,
|
| 114 |
+
audio_duration=duration,
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
if not os.path.isfile(out_path):
|
| 118 |
+
return None, f"Output file was not created: {out_path}"
|
| 119 |
+
|
| 120 |
+
progress(1.0, desc="Done.")
|
| 121 |
+
return out_path, "Genera
|