Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ from sonic import Sonic
|
|
8 |
from PIL import Image
|
9 |
import torch
|
10 |
|
11 |
-
#
|
12 |
cmd = (
|
13 |
'python3 -m pip install "huggingface_hub[cli]"; '
|
14 |
'huggingface-cli download LeonJoe13/Sonic --local-dir checkpoints; '
|
@@ -23,17 +23,15 @@ def get_md5(content):
|
|
23 |
md5hash = hashlib.md5(content)
|
24 |
return md5hash.hexdigest()
|
25 |
|
26 |
-
@spaces.GPU(duration=300) #
|
27 |
def get_video_res(img_path, audio_path, res_video_path, dynamic_scale=1.0):
|
28 |
expand_ratio = 0.5
|
29 |
min_resolution = 512
|
30 |
-
|
31 |
|
32 |
-
# 오디오
|
33 |
audio = AudioSegment.from_file(audio_path)
|
34 |
duration = len(audio) / 1000.0 # 초 단위
|
35 |
-
# 오디오 길이에 따른 프레임 수 계산 (예: 5초 -> 5*25 = 125 단계)
|
36 |
-
inference_steps = int(duration * fps)
|
37 |
print(f"Audio duration: {duration} seconds, using inference_steps: {inference_steps}")
|
38 |
|
39 |
face_info = pipe.preprocess(img_path, expand_ratio=expand_ratio)
|
@@ -45,16 +43,15 @@ def get_video_res(img_path, audio_path, res_video_path, dynamic_scale=1.0):
|
|
45 |
img_path = crop_image_path
|
46 |
os.makedirs(os.path.dirname(res_video_path), exist_ok=True)
|
47 |
|
48 |
-
#
|
49 |
pipe.process(
|
50 |
-
img_path,
|
51 |
-
audio_path,
|
52 |
-
res_video_path,
|
53 |
min_resolution=min_resolution,
|
54 |
inference_steps=inference_steps,
|
55 |
dynamic_scale=dynamic_scale
|
56 |
)
|
57 |
-
# 생성된 비디오 파일 경로 반환
|
58 |
return res_video_path
|
59 |
else:
|
60 |
return -1
|
@@ -107,7 +104,7 @@ def process_sonic(image, audio, dynamic_scale):
|
|
107 |
print(f"Generating new video with dynamic scale: {dynamic_scale}")
|
108 |
return get_video_res(image_path, audio_path, res_video_path, dynamic_scale)
|
109 |
|
110 |
-
# 예시 데이터를 위한 dummy 함수 (필요시 실제 예시
|
111 |
def get_example():
|
112 |
return []
|
113 |
|
@@ -204,5 +201,5 @@ with gr.Blocks(css=css) as demo:
|
|
204 |
</div>
|
205 |
""")
|
206 |
|
207 |
-
# 공개
|
208 |
demo.launch(share=True)
|
|
|
8 |
from PIL import Image
|
9 |
import torch
|
10 |
|
11 |
+
# 모델 초기화
|
12 |
cmd = (
|
13 |
'python3 -m pip install "huggingface_hub[cli]"; '
|
14 |
'huggingface-cli download LeonJoe13/Sonic --local-dir checkpoints; '
|
|
|
23 |
md5hash = hashlib.md5(content)
|
24 |
return md5hash.hexdigest()
|
25 |
|
26 |
+
@spaces.GPU(duration=300) # 긴 비디오 처리를 위해 duration 300초로 설정
|
27 |
def get_video_res(img_path, audio_path, res_video_path, dynamic_scale=1.0):
|
28 |
expand_ratio = 0.5
|
29 |
min_resolution = 512
|
30 |
+
inference_steps = 25 # 2초 분량의 비디오(25 프레임)로 고정
|
31 |
|
32 |
+
# 오디오 길이(참고용) 출력
|
33 |
audio = AudioSegment.from_file(audio_path)
|
34 |
duration = len(audio) / 1000.0 # 초 단위
|
|
|
|
|
35 |
print(f"Audio duration: {duration} seconds, using inference_steps: {inference_steps}")
|
36 |
|
37 |
face_info = pipe.preprocess(img_path, expand_ratio=expand_ratio)
|
|
|
43 |
img_path = crop_image_path
|
44 |
os.makedirs(os.path.dirname(res_video_path), exist_ok=True)
|
45 |
|
46 |
+
# 고정된 inference_steps(25)로 비디오 생성
|
47 |
pipe.process(
|
48 |
+
img_path,
|
49 |
+
audio_path,
|
50 |
+
res_video_path,
|
51 |
min_resolution=min_resolution,
|
52 |
inference_steps=inference_steps,
|
53 |
dynamic_scale=dynamic_scale
|
54 |
)
|
|
|
55 |
return res_video_path
|
56 |
else:
|
57 |
return -1
|
|
|
104 |
print(f"Generating new video with dynamic scale: {dynamic_scale}")
|
105 |
return get_video_res(image_path, audio_path, res_video_path, dynamic_scale)
|
106 |
|
107 |
+
# 예시 데이터를 위한 dummy 함수 (필요시 실제 예시 데이터를 추가하세요)
|
108 |
def get_example():
|
109 |
return []
|
110 |
|
|
|
201 |
</div>
|
202 |
""")
|
203 |
|
204 |
+
# 공개 링크 생성: share=True
|
205 |
demo.launch(share=True)
|