Update app.py
Browse files
app.py
CHANGED
@@ -1033,15 +1033,46 @@ def generate_avatar_animation(portrait_image, driving_audio, guidance_scale, inf
|
|
1033 |
if not os.path.exists(audio_path):
|
1034 |
return None, None, f"β μ€λμ€ νμΌμ μ°Ύμ μ μμ΅λλ€: {audio_path}"
|
1035 |
|
1036 |
-
# API
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1045 |
|
1046 |
# μμ νμΌ μμ (μλ κ²½μ°)
|
1047 |
if 'temp_portrait_path' in locals() and os.path.exists(temp_portrait_path):
|
@@ -1079,6 +1110,12 @@ def generate_avatar_animation(portrait_image, driving_audio, guidance_scale, inf
|
|
1079 |
logging.error(f"Unexpected API response: {result}")
|
1080 |
return None, None, "β API μλ΅μ΄ μμκ³Ό λ€λ¦
λλ€."
|
1081 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1082 |
except Exception as e:
|
1083 |
logging.error(f"Avatar generation error: {str(e)}")
|
1084 |
import traceback
|
|
|
1033 |
if not os.path.exists(audio_path):
|
1034 |
return None, None, f"β μ€λμ€ νμΌμ μ°Ύμ μ μμ΅λλ€: {audio_path}"
|
1035 |
|
1036 |
+
# API μ°κ²° μ¬μλ λ‘μ§
|
1037 |
+
max_retries = 3
|
1038 |
+
retry_delay = 5 # μ΄
|
1039 |
+
|
1040 |
+
for attempt in range(max_retries):
|
1041 |
+
try:
|
1042 |
+
logging.info(f"API μ°κ²° μλ {attempt + 1}/{max_retries}")
|
1043 |
+
|
1044 |
+
# νμμμμ λλ¦° Client μμ±
|
1045 |
+
# gradio_clientμ νμμμ μ€μ μ μν΄ httpx client μ€μ
|
1046 |
+
import httpx
|
1047 |
+
client = Client(
|
1048 |
+
AVATAR_API_URL,
|
1049 |
+
timeout=httpx.Timeout(60.0, connect=30.0) # μ°κ²° νμμμ 30μ΄, μ 체 νμμμ 60μ΄
|
1050 |
+
)
|
1051 |
+
|
1052 |
+
logging.info("API ν΄λΌμ΄μΈνΈ μμ± μ±κ³΅")
|
1053 |
+
|
1054 |
+
# API νΈμΆ
|
1055 |
+
result = client.predict(
|
1056 |
+
portrait_path, # μ§μ κ²½λ‘ μ λ¬
|
1057 |
+
audio_path, # μ§μ κ²½λ‘ μ λ¬
|
1058 |
+
float(guidance_scale),
|
1059 |
+
float(inference_steps),
|
1060 |
+
api_name="/generate_animation"
|
1061 |
+
)
|
1062 |
+
|
1063 |
+
# μ±κ³΅νλ©΄ 루ν μ’
λ£
|
1064 |
+
break
|
1065 |
+
|
1066 |
+
except (httpx.ConnectTimeout, httpx.TimeoutException) as e:
|
1067 |
+
logging.warning(f"μ°κ²° νμμμ (μλ {attempt + 1}/{max_retries}): {str(e)}")
|
1068 |
+
if attempt < max_retries - 1:
|
1069 |
+
logging.info(f"{retry_delay}μ΄ ν μ¬μλ...")
|
1070 |
+
time.sleep(retry_delay)
|
1071 |
+
else:
|
1072 |
+
return None, None, "β API μλ²μ μ°κ²°ν μ μμ΅λλ€. μ μ ν λ€μ μλν΄μ£ΌμΈμ."
|
1073 |
+
except Exception as e:
|
1074 |
+
# λ€λ₯Έ μμΈλ μ¦μ μ²λ¦¬
|
1075 |
+
raise e
|
1076 |
|
1077 |
# μμ νμΌ μμ (μλ κ²½μ°)
|
1078 |
if 'temp_portrait_path' in locals() and os.path.exists(temp_portrait_path):
|
|
|
1110 |
logging.error(f"Unexpected API response: {result}")
|
1111 |
return None, None, "β API μλ΅μ΄ μμκ³Ό λ€λ¦
λλ€."
|
1112 |
|
1113 |
+
except httpx.ConnectTimeout:
|
1114 |
+
logging.error("Connection timeout to API server")
|
1115 |
+
return None, None, "β API μλ² μ°κ²° μκ° μ΄κ³Ό. μλ²κ° μλ΅νμ§ μμ΅λλ€."
|
1116 |
+
except httpx.TimeoutException:
|
1117 |
+
logging.error("Request timeout")
|
1118 |
+
return None, None, "β μμ² μκ° μ΄κ³Ό. μλ² μ²λ¦¬ μκ°μ΄ λ무 κΉλλ€."
|
1119 |
except Exception as e:
|
1120 |
logging.error(f"Avatar generation error: {str(e)}")
|
1121 |
import traceback
|