Update app.py
Browse files
app.py
CHANGED
|
@@ -451,46 +451,86 @@ def create_gradio_interface():
|
|
| 451 |
if result and len(result) >= 7:
|
| 452 |
original_output, original_download, enhanced_output, enhanced_download, prompt_output, info, error = result
|
| 453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
# Gallery 데이터를 PIL Image 리스트로 변환
|
| 455 |
def convert_gallery_to_images(gallery_data):
|
| 456 |
if not gallery_data:
|
| 457 |
return []
|
| 458 |
|
| 459 |
images = []
|
| 460 |
-
|
|
|
|
|
|
|
| 461 |
try:
|
|
|
|
|
|
|
|
|
|
| 462 |
if isinstance(item, dict):
|
| 463 |
-
#
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
|
| 470 |
-
|
| 471 |
-
img_url = img_info.get('url') or img_info.get('path')
|
| 472 |
-
if img_url:
|
| 473 |
-
# URL에서 이미지 다운로드하여 PIL Image로 변환
|
| 474 |
-
response = requests.get(img_url)
|
| 475 |
-
if response.status_code == 200:
|
| 476 |
-
pil_image = Image.open(io.BytesIO(response.content))
|
| 477 |
-
images.append(pil_image)
|
| 478 |
elif isinstance(item, str):
|
| 479 |
# 직접 URL인 경우
|
| 480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
if response.status_code == 200:
|
| 482 |
pil_image = Image.open(io.BytesIO(response.content))
|
| 483 |
images.append(pil_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
except Exception as e:
|
| 485 |
-
logger.
|
|
|
|
| 486 |
continue
|
| 487 |
|
|
|
|
| 488 |
return images
|
| 489 |
|
| 490 |
# Gallery 데이터 변환
|
| 491 |
converted_original = convert_gallery_to_images(original_output)
|
| 492 |
converted_enhanced = convert_gallery_to_images(enhanced_output)
|
| 493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
# 다운로드 파일 처리 - 원본 그대로 전달
|
| 495 |
original_file = None
|
| 496 |
enhanced_file = None
|
|
|
|
| 451 |
if result and len(result) >= 7:
|
| 452 |
original_output, original_download, enhanced_output, enhanced_download, prompt_output, info, error = result
|
| 453 |
|
| 454 |
+
# 디버깅: API 응답 구조 로깅
|
| 455 |
+
logger.info(f"Original output type: {type(original_output)}")
|
| 456 |
+
logger.info(f"Enhanced output type: {type(enhanced_output)}")
|
| 457 |
+
if original_output:
|
| 458 |
+
logger.info(f"Original output first item: {type(original_output[0]) if original_output else 'Empty'}")
|
| 459 |
+
if original_output and isinstance(original_output[0], dict):
|
| 460 |
+
logger.info(f"Original output keys: {list(original_output[0].keys())}")
|
| 461 |
+
|
| 462 |
# Gallery 데이터를 PIL Image 리스트로 변환
|
| 463 |
def convert_gallery_to_images(gallery_data):
|
| 464 |
if not gallery_data:
|
| 465 |
return []
|
| 466 |
|
| 467 |
images = []
|
| 468 |
+
logger.info(f"Converting gallery data, length: {len(gallery_data)}")
|
| 469 |
+
|
| 470 |
+
for i, item in enumerate(gallery_data):
|
| 471 |
try:
|
| 472 |
+
logger.info(f"Processing gallery item {i}: {type(item)}")
|
| 473 |
+
|
| 474 |
+
img_url = None
|
| 475 |
if isinstance(item, dict):
|
| 476 |
+
# 여러 가지 가능한 구조 시도
|
| 477 |
+
if 'image' in item:
|
| 478 |
+
if isinstance(item['image'], dict):
|
| 479 |
+
img_url = item['image'].get('url') or item['image'].get('path')
|
| 480 |
+
else:
|
| 481 |
+
img_url = item['image']
|
| 482 |
+
elif 'url' in item:
|
| 483 |
+
img_url = item['url']
|
| 484 |
+
elif 'path' in item:
|
| 485 |
+
img_url = item['path']
|
| 486 |
|
| 487 |
+
logger.info(f"Extracted URL from dict: {img_url}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
elif isinstance(item, str):
|
| 489 |
# 직접 URL인 경우
|
| 490 |
+
img_url = item
|
| 491 |
+
logger.info(f"Direct URL: {img_url}")
|
| 492 |
+
|
| 493 |
+
if img_url:
|
| 494 |
+
# URL이 상대 경로인 경우 절대 경로로 변환
|
| 495 |
+
if img_url.startswith('/'):
|
| 496 |
+
img_url = f"https://happydoggg-49493h.hf.space/gradio_api/file={img_url}"
|
| 497 |
+
elif not img_url.startswith('http'):
|
| 498 |
+
img_url = f"https://happydoggg-49493h.hf.space/gradio_api/file={img_url}"
|
| 499 |
+
|
| 500 |
+
logger.info(f"Final URL: {img_url}")
|
| 501 |
+
|
| 502 |
+
# URL에서 이���지 다운로드하여 PIL Image로 변환
|
| 503 |
+
response = requests.get(img_url)
|
| 504 |
if response.status_code == 200:
|
| 505 |
pil_image = Image.open(io.BytesIO(response.content))
|
| 506 |
images.append(pil_image)
|
| 507 |
+
logger.info(f"Successfully converted image {i}")
|
| 508 |
+
else:
|
| 509 |
+
logger.warning(f"Failed to download image from {img_url}, status: {response.status_code}")
|
| 510 |
+
else:
|
| 511 |
+
logger.warning(f"No URL found in item {i}: {item}")
|
| 512 |
+
|
| 513 |
except Exception as e:
|
| 514 |
+
logger.error(f"Failed to convert gallery item {i}: {e}")
|
| 515 |
+
logger.error(f"Item content: {item}")
|
| 516 |
continue
|
| 517 |
|
| 518 |
+
logger.info(f"Converted {len(images)} images from gallery data")
|
| 519 |
return images
|
| 520 |
|
| 521 |
# Gallery 데이터 변환
|
| 522 |
converted_original = convert_gallery_to_images(original_output)
|
| 523 |
converted_enhanced = convert_gallery_to_images(enhanced_output)
|
| 524 |
|
| 525 |
+
# 변환된 이미지가 없는 경우, 원본 데이터를 그대로 반환 시도
|
| 526 |
+
if not converted_original and original_output:
|
| 527 |
+
logger.info("No converted original images, trying to use original data directly")
|
| 528 |
+
converted_original = original_output
|
| 529 |
+
|
| 530 |
+
if not converted_enhanced and enhanced_output:
|
| 531 |
+
logger.info("No converted enhanced images, trying to use enhanced data directly")
|
| 532 |
+
converted_enhanced = enhanced_output
|
| 533 |
+
|
| 534 |
# 다운로드 파일 처리 - 원본 그대로 전달
|
| 535 |
original_file = None
|
| 536 |
enhanced_file = None
|