ginipick commited on
Commit
9030b5a
Β·
verified Β·
1 Parent(s): 88d099b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -22
app.py CHANGED
@@ -1041,13 +1041,8 @@ def generate_avatar_animation(portrait_image, driving_audio, guidance_scale, inf
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
 
@@ -1063,16 +1058,17 @@ def generate_avatar_animation(portrait_image, driving_audio, guidance_scale, inf
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,12 +1106,6 @@ def generate_avatar_animation(portrait_image, driving_audio, guidance_scale, inf
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
 
1041
  try:
1042
  logging.info(f"API μ—°κ²° μ‹œλ„ {attempt + 1}/{max_retries}")
1043
 
1044
+ # κ°„λ‹¨ν•œ Client 생성 (timeout λ§€κ°œλ³€μˆ˜ 없이)
1045
+ client = Client(AVATAR_API_URL)
 
 
 
 
 
1046
 
1047
  logging.info("API ν΄λΌμ΄μ–ΈνŠΈ 생성 성곡")
1048
 
 
1058
  # μ„±κ³΅ν•˜λ©΄ 루프 μ’…λ£Œ
1059
  break
1060
 
 
 
 
 
 
 
 
1061
  except Exception as e:
1062
+ logging.warning(f"API 호좜 였λ₯˜ (μ‹œλ„ {attempt + 1}/{max_retries}): {str(e)}")
1063
+ if "Connection" in str(e) or "Timeout" in str(e):
1064
+ if attempt < max_retries - 1:
1065
+ logging.info(f"{retry_delay}초 ν›„ μž¬μ‹œλ„...")
1066
+ time.sleep(retry_delay)
1067
+ else:
1068
+ return None, None, "❌ API μ„œλ²„μ— μ—°κ²°ν•  수 μ—†μŠ΅λ‹ˆλ‹€. μž μ‹œ ν›„ λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”."
1069
+ else:
1070
+ # λ‹€λ₯Έ μ˜ˆμ™ΈλŠ” μ¦‰μ‹œ 처리
1071
+ raise e
1072
 
1073
  # μž„μ‹œ 파일 μ‚­μ œ (μžˆλŠ” 경우)
1074
  if 'temp_portrait_path' in locals() and os.path.exists(temp_portrait_path):
 
1106
  logging.error(f"Unexpected API response: {result}")
1107
  return None, None, "❌ API 응닡이 μ˜ˆμƒκ³Ό λ‹€λ¦…λ‹ˆλ‹€."
1108
 
 
 
 
 
 
 
1109
  except Exception as e:
1110
  logging.error(f"Avatar generation error: {str(e)}")
1111
  import traceback