Update app.py
Browse files
app.py
CHANGED
@@ -446,7 +446,85 @@ def create_gradio_interface():
|
|
446 |
param_14=enable_enhancement,
|
447 |
api_name="/check_password"
|
448 |
)
|
449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
450 |
finally:
|
451 |
# ์์ ํ์ผ ์ ๋ฆฌ
|
452 |
if os.path.exists(temp_path):
|
@@ -457,6 +535,7 @@ def create_gradio_interface():
|
|
457 |
|
458 |
except Exception as e:
|
459 |
logger.error(f"Error in check_password: {e}")
|
|
|
460 |
return ([], None, [], None, "", "", f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
461 |
|
462 |
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
|
|
446 |
param_14=enable_enhancement,
|
447 |
api_name="/check_password"
|
448 |
)
|
449 |
+
|
450 |
+
# API ์๋ต ์ฒ๋ฆฌ - ๋์
๋๋ฆฌ๋ฅผ ์๋ณธ์ฒ๋ผ PIL Image๋ก ๋ณํ
|
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 |
+
for item in gallery_data:
|
461 |
+
try:
|
462 |
+
if isinstance(item, dict):
|
463 |
+
# ๋์
๋๋ฆฌ์์ ์ด๋ฏธ์ง URL/๊ฒฝ๋ก ์ถ์ถ
|
464 |
+
img_info = None
|
465 |
+
if 'image' in item and isinstance(item['image'], dict):
|
466 |
+
img_info = item['image']
|
467 |
+
elif 'path' in item or 'url' in item:
|
468 |
+
img_info = item
|
469 |
+
|
470 |
+
if img_info:
|
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 |
+
response = requests.get(item)
|
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.warning(f"Failed to convert gallery item to PIL Image: {e}")
|
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
|
497 |
+
|
498 |
+
# ์๋ณธ ์ด๋ฏธ์ง ํ์ผ ์์ฑ
|
499 |
+
if converted_original:
|
500 |
+
try:
|
501 |
+
original_file_path = f"original_image.{output_format}"
|
502 |
+
converted_original[0].save(original_file_path, format=output_format.upper())
|
503 |
+
original_file = original_file_path
|
504 |
+
except Exception as e:
|
505 |
+
logger.error(f"Error saving original image: {e}")
|
506 |
+
|
507 |
+
# ๊ฐ์ ๋ ์ด๋ฏธ์ง ํ์ผ ์์ฑ
|
508 |
+
if converted_enhanced:
|
509 |
+
try:
|
510 |
+
enhanced_file_path = f"enhanced_image.{output_format}"
|
511 |
+
converted_enhanced[0].save(enhanced_file_path, format=output_format.upper())
|
512 |
+
enhanced_file = enhanced_file_path
|
513 |
+
except Exception as e:
|
514 |
+
logger.error(f"Error saving enhanced image: {e}")
|
515 |
+
|
516 |
+
return (
|
517 |
+
converted_original, # PIL Image ๋ฆฌ์คํธ
|
518 |
+
original_file, # ๋ค์ด๋ก๋ ํ์ผ ๊ฒฝ๋ก
|
519 |
+
converted_enhanced, # PIL Image ๋ฆฌ์คํธ
|
520 |
+
enhanced_file, # ๋ค์ด๋ก๋ ํ์ผ ๊ฒฝ๋ก
|
521 |
+
prompt_output, # ํ๋กฌํํธ ํ
์คํธ
|
522 |
+
info, # ์ฒ๋ฆฌ ์ ๋ณด
|
523 |
+
error # ์ค๋ฅ ๋ฉ์์ง
|
524 |
+
)
|
525 |
+
else:
|
526 |
+
return ([], None, [], None, "", "", "API ์๋ต์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.")
|
527 |
+
|
528 |
finally:
|
529 |
# ์์ ํ์ผ ์ ๋ฆฌ
|
530 |
if os.path.exists(temp_path):
|
|
|
535 |
|
536 |
except Exception as e:
|
537 |
logger.error(f"Error in check_password: {e}")
|
538 |
+
logger.error(f"Full traceback: {traceback.format_exc()}")
|
539 |
return ([], None, [], None, "", "", f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
540 |
|
541 |
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|