Update app.py
Browse files
app.py
CHANGED
@@ -1001,48 +1001,82 @@ def generate_avatar_animation(portrait_image, driving_audio, guidance_scale, inf
|
|
1001 |
# ์ํ ์
๋ฐ์ดํธ
|
1002 |
status = "์๋ฐํ ์์ฑ ์์..."
|
1003 |
|
1004 |
-
# ์ด๋ฏธ์ง
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1011 |
|
1012 |
# ์ค๋์ค ๊ฒฝ๋ก ํ์ธ
|
1013 |
-
|
1014 |
-
audio_path = driving_audio
|
1015 |
-
else:
|
1016 |
-
audio_path = driving_audio
|
1017 |
|
1018 |
-
|
1019 |
-
logging.info(f"
|
|
|
1020 |
logging.info(f"Guidance Scale: {guidance_scale}")
|
1021 |
logging.info(f"Inference Steps: {inference_steps}")
|
1022 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1023 |
# API ํธ์ถ
|
1024 |
client = Client(AVATAR_API_URL)
|
1025 |
result = client.predict(
|
1026 |
-
|
1027 |
-
|
1028 |
float(guidance_scale),
|
1029 |
float(inference_steps),
|
1030 |
api_name="/generate_animation"
|
1031 |
)
|
1032 |
|
1033 |
-
# ์์ ํ์ผ ์ญ์
|
1034 |
-
os.
|
|
|
1035 |
|
|
|
1036 |
if result and len(result) >= 2:
|
1037 |
animation_result = result[0]
|
1038 |
comparison_result = result[1]
|
1039 |
|
1040 |
-
#
|
1041 |
-
|
1042 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1043 |
|
1044 |
return animation_video, comparison_video, "โ
์๋ฐํ ์ ๋๋ฉ์ด์
์์ฑ ์๋ฃ!"
|
1045 |
else:
|
|
|
1046 |
return None, None, "โ API ์๋ต์ด ์์๊ณผ ๋ค๋ฆ
๋๋ค."
|
1047 |
|
1048 |
except Exception as e:
|
@@ -1493,7 +1527,8 @@ with demo:
|
|
1493 |
|
1494 |
avatar_portrait = gr.Image(
|
1495 |
label="์ด์ํ ์ด๋ฏธ์ง (์๋ฌด ๋น์จ ๊ฐ๋ฅ)",
|
1496 |
-
type="filepath"
|
|
|
1497 |
)
|
1498 |
|
1499 |
with gr.Group(elem_classes="panel-box"):
|
|
|
1001 |
# ์ํ ์
๋ฐ์ดํธ
|
1002 |
status = "์๋ฐํ ์์ฑ ์์..."
|
1003 |
|
1004 |
+
# ์ด๋ฏธ์ง ์ฒ๋ฆฌ - filepath๋ก ๋ฐ์ผ๋ฏ๋ก ์ง์ ์ฌ์ฉ
|
1005 |
+
portrait_path = portrait_image
|
1006 |
+
|
1007 |
+
# ์ด๋ฏธ์ง๊ฐ ์ค์ ๋ก ์กด์ฌํ๋์ง ํ์ธ
|
1008 |
+
if not os.path.exists(portrait_path):
|
1009 |
+
# ๋ง์ฝ numpy array๋ PIL ์ด๋ฏธ์ง๋ก ์๋ค๋ฉด ์ ์ฅ
|
1010 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as fp:
|
1011 |
+
temp_portrait_path = fp.name
|
1012 |
+
if isinstance(portrait_image, np.ndarray):
|
1013 |
+
Image.fromarray(portrait_image).save(temp_portrait_path)
|
1014 |
+
elif isinstance(portrait_image, Image.Image):
|
1015 |
+
portrait_image.save(temp_portrait_path)
|
1016 |
+
else:
|
1017 |
+
return None, None, "โ ์ด๋ฏธ์ง ํ์์ ์ธ์ํ ์ ์์ต๋๋ค."
|
1018 |
+
portrait_path = temp_portrait_path
|
1019 |
|
1020 |
# ์ค๋์ค ๊ฒฝ๋ก ํ์ธ
|
1021 |
+
audio_path = driving_audio
|
|
|
|
|
|
|
1022 |
|
1023 |
+
# ๊ฒฝ๋ก ๋ก๊น
|
1024 |
+
logging.info(f"Portrait path: {portrait_path}")
|
1025 |
+
logging.info(f"Audio path: {audio_path}")
|
1026 |
logging.info(f"Guidance Scale: {guidance_scale}")
|
1027 |
logging.info(f"Inference Steps: {inference_steps}")
|
1028 |
|
1029 |
+
# ํ์ผ ์กด์ฌ ํ์ธ
|
1030 |
+
if not os.path.exists(portrait_path):
|
1031 |
+
return None, None, f"โ ์ด๋ฏธ์ง ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค: {portrait_path}"
|
1032 |
+
|
1033 |
+
if not os.path.exists(audio_path):
|
1034 |
+
return None, None, f"โ ์ค๋์ค ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค: {audio_path}"
|
1035 |
+
|
1036 |
# API ํธ์ถ
|
1037 |
client = Client(AVATAR_API_URL)
|
1038 |
result = client.predict(
|
1039 |
+
portrait_path, # ์ง์ ๊ฒฝ๋ก ์ ๋ฌ
|
1040 |
+
audio_path, # ์ง์ ๊ฒฝ๋ก ์ ๋ฌ
|
1041 |
float(guidance_scale),
|
1042 |
float(inference_steps),
|
1043 |
api_name="/generate_animation"
|
1044 |
)
|
1045 |
|
1046 |
+
# ์์ ํ์ผ ์ญ์ (์๋ ๊ฒฝ์ฐ)
|
1047 |
+
if 'temp_portrait_path' in locals() and os.path.exists(temp_portrait_path):
|
1048 |
+
os.unlink(temp_portrait_path)
|
1049 |
|
1050 |
+
# ๊ฒฐ๊ณผ ์ฒ๋ฆฌ
|
1051 |
if result and len(result) >= 2:
|
1052 |
animation_result = result[0]
|
1053 |
comparison_result = result[1]
|
1054 |
|
1055 |
+
# ๊ฒฐ๊ณผ๊ฐ dict์ธ์ง ์ง์ ๊ฒฝ๋ก์ธ์ง ํ์ธ
|
1056 |
+
if isinstance(animation_result, dict):
|
1057 |
+
animation_video = animation_result.get("video")
|
1058 |
+
else:
|
1059 |
+
animation_video = animation_result
|
1060 |
+
|
1061 |
+
if isinstance(comparison_result, dict):
|
1062 |
+
comparison_video = comparison_result.get("video")
|
1063 |
+
else:
|
1064 |
+
comparison_video = comparison_result
|
1065 |
+
|
1066 |
+
# ๋น๋์ค ํ์ผ ์กด์ฌ ํ์ธ
|
1067 |
+
if animation_video and os.path.exists(str(animation_video)):
|
1068 |
+
logging.info(f"Animation video created: {animation_video}")
|
1069 |
+
else:
|
1070 |
+
logging.warning(f"Animation video not found or invalid: {animation_video}")
|
1071 |
+
|
1072 |
+
if comparison_video and os.path.exists(str(comparison_video)):
|
1073 |
+
logging.info(f"Comparison video created: {comparison_video}")
|
1074 |
+
else:
|
1075 |
+
logging.warning(f"Comparison video not found or invalid: {comparison_video}")
|
1076 |
|
1077 |
return animation_video, comparison_video, "โ
์๋ฐํ ์ ๋๋ฉ์ด์
์์ฑ ์๋ฃ!"
|
1078 |
else:
|
1079 |
+
logging.error(f"Unexpected API response: {result}")
|
1080 |
return None, None, "โ API ์๋ต์ด ์์๊ณผ ๋ค๋ฆ
๋๋ค."
|
1081 |
|
1082 |
except Exception as e:
|
|
|
1527 |
|
1528 |
avatar_portrait = gr.Image(
|
1529 |
label="์ด์ํ ์ด๋ฏธ์ง (์๋ฌด ๋น์จ ๊ฐ๋ฅ)",
|
1530 |
+
type="filepath",
|
1531 |
+
sources=["upload"]
|
1532 |
)
|
1533 |
|
1534 |
with gr.Group(elem_classes="panel-box"):
|