ginipick commited on
Commit
df5bbd7
Β·
verified Β·
1 Parent(s): f69df47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -9
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
- 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):
@@ -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