ginipick commited on
Commit
f69df47
ยท
verified ยท
1 Parent(s): d06a374

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -21
app.py CHANGED
@@ -1001,48 +1001,82 @@ def generate_avatar_animation(portrait_image, driving_audio, guidance_scale, inf
1001
  # ์ƒํƒœ ์—…๋ฐ์ดํŠธ
1002
  status = "์•„๋ฐ”ํƒ€ ์ƒ์„ฑ ์‹œ์ž‘..."
1003
 
1004
- # ์ด๋ฏธ์ง€ ์ €์žฅ
1005
- with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as fp:
1006
- portrait_path = fp.name
1007
- if isinstance(portrait_image, np.ndarray):
1008
- Image.fromarray(portrait_image).save(portrait_path)
1009
- else:
1010
- Image.open(portrait_image).save(portrait_path)
 
 
 
 
 
 
 
 
1011
 
1012
  # ์˜ค๋””์˜ค ๊ฒฝ๋กœ ํ™•์ธ
1013
- if isinstance(driving_audio, str):
1014
- audio_path = driving_audio
1015
- else:
1016
- audio_path = driving_audio
1017
 
1018
- logging.info(f"Portrait: {portrait_path}")
1019
- logging.info(f"Audio: {audio_path}")
 
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
- handle_file(portrait_path),
1027
- handle_file(audio_path),
1028
  float(guidance_scale),
1029
  float(inference_steps),
1030
  api_name="/generate_animation"
1031
  )
1032
 
1033
- # ์ž„์‹œ ํŒŒ์ผ ์‚ญ์ œ
1034
- os.unlink(portrait_path)
 
1035
 
 
1036
  if result and len(result) >= 2:
1037
  animation_result = result[0]
1038
  comparison_result = result[1]
1039
 
1040
- # ๋น„๋””์˜ค ๊ฒฝ๋กœ ์ถ”์ถœ
1041
- animation_video = animation_result.get("video") if isinstance(animation_result, dict) else None
1042
- comparison_video = comparison_result.get("video") if isinstance(comparison_result, dict) else None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"):