Spaces:
Sleeping
Sleeping
Update modules/image_analyzer.py
Browse files- modules/image_analyzer.py +15 -20
modules/image_analyzer.py
CHANGED
|
@@ -93,42 +93,37 @@ def load_trait_mappings():
|
|
| 93 |
}
|
| 94 |
return default_mappings
|
| 95 |
|
| 96 |
-
def analyze_image(
|
| 97 |
"""
|
| 98 |
이미지를 분석하여 물리적 특성과 그에 따른 성격 특성을 반환합니다.
|
| 99 |
|
| 100 |
Args:
|
| 101 |
-
|
| 102 |
|
| 103 |
Returns:
|
| 104 |
이미지 분석 결과와 추천 특성값
|
| 105 |
"""
|
| 106 |
-
if
|
| 107 |
print("이미지가 없습니다.")
|
| 108 |
return {}, 50, 50, 50, 50, 50, 50, "", ""
|
| 109 |
|
| 110 |
try:
|
| 111 |
-
print(f"이미지 분석 시작: {
|
| 112 |
|
| 113 |
# 이미지 로드 시도
|
| 114 |
try:
|
| 115 |
-
#
|
| 116 |
-
if isinstance(
|
| 117 |
-
img =
|
| 118 |
-
print(f"PIL 이미지 로드 성공: {img.format}, {img.size}, {img.mode}")
|
| 119 |
-
# 파일 경로인 경우 열기
|
| 120 |
-
elif isinstance(image, str):
|
| 121 |
-
img = Image.open(image)
|
| 122 |
print(f"파일 경로에서 이미지 로드 성공: {img.format}, {img.size}, {img.mode}")
|
| 123 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
else:
|
| 125 |
-
print(f"다른 형식의 이미지 데이터: {type(
|
| 126 |
-
|
| 127 |
-
img = Image.open(image)
|
| 128 |
-
elif isinstance(image, bytes): # 바이트인 경우
|
| 129 |
-
img = Image.open(io.BytesIO(image))
|
| 130 |
-
else:
|
| 131 |
-
raise ValueError(f"지원하지 않는 이미지 형식: {type(image)}")
|
| 132 |
except Exception as img_error:
|
| 133 |
print(f"이미지 로드 실패: {str(img_error)}")
|
| 134 |
return {}, 50, 50, 50, 50, 50, 50, "", ""
|
|
@@ -165,7 +160,7 @@ def analyze_image(image):
|
|
| 165 |
"유머감각": 50
|
| 166 |
}
|
| 167 |
|
| 168 |
-
# 특성 적용
|
| 169 |
|
| 170 |
# 분석 결과 반환
|
| 171 |
analysis_result = {
|
|
|
|
| 93 |
}
|
| 94 |
return default_mappings
|
| 95 |
|
| 96 |
+
def analyze_image(image_path):
|
| 97 |
"""
|
| 98 |
이미지를 분석하여 물리적 특성과 그에 따른 성격 특성을 반환합니다.
|
| 99 |
|
| 100 |
Args:
|
| 101 |
+
image_path: 파일 경로 문자열
|
| 102 |
|
| 103 |
Returns:
|
| 104 |
이미지 분석 결과와 추천 특성값
|
| 105 |
"""
|
| 106 |
+
if image_path is None:
|
| 107 |
print("이미지가 없습니다.")
|
| 108 |
return {}, 50, 50, 50, 50, 50, 50, "", ""
|
| 109 |
|
| 110 |
try:
|
| 111 |
+
print(f"이미지 분석 시작: {image_path}")
|
| 112 |
|
| 113 |
# 이미지 로드 시도
|
| 114 |
try:
|
| 115 |
+
# 파일 경로 처리
|
| 116 |
+
if isinstance(image_path, str):
|
| 117 |
+
img = Image.open(image_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
print(f"파일 경로에서 이미지 로드 성공: {img.format}, {img.size}, {img.mode}")
|
| 119 |
+
# File 컴포넌트에서 반환하는 경로 형식 처리
|
| 120 |
+
elif isinstance(image_path, dict) and 'path' in image_path:
|
| 121 |
+
img = Image.open(image_path['path'])
|
| 122 |
+
print(f"File 컴포넌트에서 이미지 로드 성공: {img.format}, {img.size}, {img.mode}")
|
| 123 |
+
# 기타 타입 처리
|
| 124 |
else:
|
| 125 |
+
print(f"다른 형식의 이미지 데이터: {type(image_path)}")
|
| 126 |
+
raise ValueError(f"지원하지 않는 이미지 형식: {type(image_path)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
except Exception as img_error:
|
| 128 |
print(f"이미지 로드 실패: {str(img_error)}")
|
| 129 |
return {}, 50, 50, 50, 50, 50, 50, "", ""
|
|
|
|
| 160 |
"유머감각": 50
|
| 161 |
}
|
| 162 |
|
| 163 |
+
# 특성 적용...
|
| 164 |
|
| 165 |
# 분석 결과 반환
|
| 166 |
analysis_result = {
|