Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -31,24 +31,21 @@ os.makedirs(res_path, exist_ok=True)
|
|
31 |
@spaces.GPU(duration=600) # 긴 비디오 처리를 위해 duration 600초로 설정 (10분)
|
32 |
def get_video_res(img_path, audio_path, res_video_path, dynamic_scale=1.0):
|
33 |
# ============================
|
34 |
-
#
|
35 |
-
# 2) 원본 비율 유지(크롭 제거)
|
36 |
# ============================
|
37 |
-
|
38 |
-
## 수정됨: expand_ratio를 0으로 (기존 0.5)
|
39 |
-
expand_ratio = 0.0
|
40 |
|
|
|
41 |
min_resolution = 512
|
42 |
|
43 |
-
|
44 |
audio = AudioSegment.from_file(audio_path)
|
45 |
duration = len(audio) / 1000.0 # 초 단위
|
46 |
|
47 |
# 오디오 길이에 따라 inference_steps 계산 (초당 약 12.5 프레임)
|
48 |
-
# 최소 25 프레임, 최대 750 프레임 (60초
|
49 |
inference_steps = min(max(int(duration * 12.5), 25), 750)
|
50 |
|
51 |
-
print(f"Audio duration: {duration} seconds, using inference_steps: {inference_steps}")
|
52 |
|
53 |
# 얼굴 인식 (face_info는 참고용)
|
54 |
face_info = pipe.preprocess(img_path, expand_ratio=expand_ratio)
|
@@ -57,8 +54,7 @@ def get_video_res(img_path, audio_path, res_video_path, dynamic_scale=1.0):
|
|
57 |
# 얼굴이 하나라도 검출되면(>0), 원본 이미지 비율 유지
|
58 |
if face_info['face_num'] > 0:
|
59 |
os.makedirs(os.path.dirname(res_video_path), exist_ok=True)
|
60 |
-
|
61 |
-
# 원본 이미지를 그대로 전달
|
62 |
pipe.process(
|
63 |
img_path,
|
64 |
audio_path,
|
@@ -96,7 +92,7 @@ def process_sonic(image, audio, dynamic_scale):
|
|
96 |
audio_segment = audio_segment.set_frame_rate(sampling_rate)
|
97 |
|
98 |
# 오디오 길이 제한 확인 (최대 60초)
|
99 |
-
MAX_DURATION_MS = 60000 # 60초
|
100 |
if len(audio_segment) > MAX_DURATION_MS:
|
101 |
print(f"Audio longer than 60 seconds ({len(audio_segment)/1000:.2f}s). Truncating to 60 seconds.")
|
102 |
audio_segment = audio_segment[:MAX_DURATION_MS]
|
@@ -112,7 +108,7 @@ def process_sonic(image, audio, dynamic_scale):
|
|
112 |
if not os.path.exists(audio_path):
|
113 |
audio_segment.export(audio_path, format="wav")
|
114 |
|
115 |
-
# 캐시된 결과가 있으면 바로
|
116 |
if os.path.exists(res_video_path):
|
117 |
print(f"Using cached result: {res_video_path}")
|
118 |
return res_video_path
|
@@ -120,7 +116,7 @@ def process_sonic(image, audio, dynamic_scale):
|
|
120 |
print(f"Generating new video with dynamic scale: {dynamic_scale}")
|
121 |
return get_video_res(image_path, audio_path, res_video_path, dynamic_scale)
|
122 |
|
123 |
-
# 예시 데이터를 위한 dummy 함수
|
124 |
def get_example():
|
125 |
return []
|
126 |
|
@@ -217,4 +213,4 @@ with gr.Blocks(css=css) as demo:
|
|
217 |
""")
|
218 |
|
219 |
# 공개 링크 생성
|
220 |
-
demo.launch(share=True)
|
|
|
31 |
@spaces.GPU(duration=600) # 긴 비디오 처리를 위해 duration 600초로 설정 (10분)
|
32 |
def get_video_res(img_path, audio_path, res_video_path, dynamic_scale=1.0):
|
33 |
# ============================
|
34 |
+
# 최대 60초까지 오디오를 반영
|
|
|
35 |
# ============================
|
|
|
|
|
|
|
36 |
|
37 |
+
expand_ratio = 0.0
|
38 |
min_resolution = 512
|
39 |
|
40 |
+
# pydub으로 오디오 길이 계산
|
41 |
audio = AudioSegment.from_file(audio_path)
|
42 |
duration = len(audio) / 1000.0 # 초 단위
|
43 |
|
44 |
# 오디오 길이에 따라 inference_steps 계산 (초당 약 12.5 프레임)
|
45 |
+
# 최소 25 프레임, 최대 750 프레임 (60초 => 60*12.5=750)
|
46 |
inference_steps = min(max(int(duration * 12.5), 25), 750)
|
47 |
|
48 |
+
print(f"Audio duration: {duration:.2f} seconds, using inference_steps: {inference_steps}")
|
49 |
|
50 |
# 얼굴 인식 (face_info는 참고용)
|
51 |
face_info = pipe.preprocess(img_path, expand_ratio=expand_ratio)
|
|
|
54 |
# 얼굴이 하나라도 검출되면(>0), 원본 이미지 비율 유지
|
55 |
if face_info['face_num'] > 0:
|
56 |
os.makedirs(os.path.dirname(res_video_path), exist_ok=True)
|
57 |
+
|
|
|
58 |
pipe.process(
|
59 |
img_path,
|
60 |
audio_path,
|
|
|
92 |
audio_segment = audio_segment.set_frame_rate(sampling_rate)
|
93 |
|
94 |
# 오디오 길이 제한 확인 (최대 60초)
|
95 |
+
MAX_DURATION_MS = 60000 # 60초
|
96 |
if len(audio_segment) > MAX_DURATION_MS:
|
97 |
print(f"Audio longer than 60 seconds ({len(audio_segment)/1000:.2f}s). Truncating to 60 seconds.")
|
98 |
audio_segment = audio_segment[:MAX_DURATION_MS]
|
|
|
108 |
if not os.path.exists(audio_path):
|
109 |
audio_segment.export(audio_path, format="wav")
|
110 |
|
111 |
+
# 캐시된 결과가 있으면 바로 사용
|
112 |
if os.path.exists(res_video_path):
|
113 |
print(f"Using cached result: {res_video_path}")
|
114 |
return res_video_path
|
|
|
116 |
print(f"Generating new video with dynamic scale: {dynamic_scale}")
|
117 |
return get_video_res(image_path, audio_path, res_video_path, dynamic_scale)
|
118 |
|
119 |
+
# 예시 데이터를 위한 dummy 함수
|
120 |
def get_example():
|
121 |
return []
|
122 |
|
|
|
213 |
""")
|
214 |
|
215 |
# 공개 링크 생성
|
216 |
+
demo.launch(share=True)
|