Update app.py
Browse files
app.py
CHANGED
|
@@ -188,9 +188,18 @@ def api_generate_prompt_with_password_check(password, bg_type, simple, studio, n
|
|
| 188 |
def api_check_password(password, image_file, bg_type, simple, studio, nature, indoor, special, jewelry, special_effects, request_text, quality_level, aspect_ratio, output_format, enable_enhancement):
|
| 189 |
"""์ด๋ฏธ์ง ์ฒ๋ฆฌ API ํธ์ถ"""
|
| 190 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
result = client.predict(
|
| 192 |
password=password,
|
| 193 |
-
param_1=
|
| 194 |
param_2=bg_type,
|
| 195 |
param_3=simple,
|
| 196 |
param_4=studio,
|
|
@@ -209,6 +218,8 @@ def api_check_password(password, image_file, bg_type, simple, studio, nature, in
|
|
| 209 |
return result
|
| 210 |
except Exception as e:
|
| 211 |
logger.error(f"Error calling check_password API: {e}")
|
|
|
|
|
|
|
| 212 |
return [], None, [], None, "", "", f"API ํธ์ถ ์ค๋ฅ: {str(e)}"
|
| 213 |
|
| 214 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ (์์ ํ ๋์ผํ UI)
|
|
@@ -395,25 +406,42 @@ def create_gradio_interface():
|
|
| 395 |
if image is None:
|
| 396 |
return [], None, [], None, "", "", "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ผ ํฉ๋๋ค."
|
| 397 |
|
| 398 |
-
|
| 399 |
-
temp_path = save_uploaded_file(image)
|
| 400 |
-
if temp_path is None:
|
| 401 |
-
return [], None, [], None, "", "", "์ด๋ฏธ์ง ์ฒ๋ฆฌ์ ์คํจํ์ต๋๋ค."
|
| 402 |
-
|
| 403 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
# API ํธ์ถ
|
| 405 |
result = api_check_password(
|
| 406 |
password, temp_path, bg_type, simple, studio, nature, indoor, special, jewelry, special_effects,
|
| 407 |
request_text, quality_level, aspect_ratio, output_format, enable_enhancement
|
| 408 |
)
|
| 409 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
finally:
|
| 411 |
# ์์ ํ์ผ ์ ๋ฆฌ
|
| 412 |
-
if os.path.exists(temp_path):
|
| 413 |
try:
|
| 414 |
os.remove(temp_path)
|
| 415 |
-
|
| 416 |
-
|
|
|
|
| 417 |
|
| 418 |
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ (์๋ณธ๊ณผ ๋์ผํ API ์ด๋ฆ)
|
| 419 |
generate_prompt_btn.click(
|
|
|
|
| 188 |
def api_check_password(password, image_file, bg_type, simple, studio, nature, indoor, special, jewelry, special_effects, request_text, quality_level, aspect_ratio, output_format, enable_enhancement):
|
| 189 |
"""์ด๋ฏธ์ง ์ฒ๋ฆฌ API ํธ์ถ"""
|
| 190 |
try:
|
| 191 |
+
# ์ด๋ฏธ์ง ํ์ผ์ gradio_client์ handle_file๋ก ์ฒ๋ฆฌ
|
| 192 |
+
from gradio_client import handle_file
|
| 193 |
+
|
| 194 |
+
# ํ์ผ์ด ๊ฒฝ๋ก์ธ ๊ฒฝ์ฐ handle_file๋ก ๋ํ
|
| 195 |
+
if isinstance(image_file, str):
|
| 196 |
+
image_handle = handle_file(image_file)
|
| 197 |
+
else:
|
| 198 |
+
image_handle = image_file
|
| 199 |
+
|
| 200 |
result = client.predict(
|
| 201 |
password=password,
|
| 202 |
+
param_1=image_handle, # handle_file๋ก ์ฒ๋ฆฌ๋ ์ด๋ฏธ์ง
|
| 203 |
param_2=bg_type,
|
| 204 |
param_3=simple,
|
| 205 |
param_4=studio,
|
|
|
|
| 218 |
return result
|
| 219 |
except Exception as e:
|
| 220 |
logger.error(f"Error calling check_password API: {e}")
|
| 221 |
+
# ๋ ์์ธํ ์ค๋ฅ ์ ๋ณด ๋ก๊น
|
| 222 |
+
logger.error(f"Full error details: {traceback.format_exc()}")
|
| 223 |
return [], None, [], None, "", "", f"API ํธ์ถ ์ค๋ฅ: {str(e)}"
|
| 224 |
|
| 225 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ (์์ ํ ๋์ผํ UI)
|
|
|
|
| 406 |
if image is None:
|
| 407 |
return [], None, [], None, "", "", "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ผ ํฉ๋๋ค."
|
| 408 |
|
| 409 |
+
temp_path = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
try:
|
| 411 |
+
# PIL Image๋ฅผ ์์ ํ์ผ๋ก ์ ์ฅ
|
| 412 |
+
if isinstance(image, Image.Image):
|
| 413 |
+
temp_path = tempfile.mktemp(suffix='.png')
|
| 414 |
+
image.save(temp_path, format='PNG')
|
| 415 |
+
logger.info(f"Saved PIL image to temporary file: {temp_path}")
|
| 416 |
+
else:
|
| 417 |
+
temp_path = save_uploaded_file(image)
|
| 418 |
+
|
| 419 |
+
if temp_path is None:
|
| 420 |
+
return [], None, [], None, "", "", "์ด๋ฏธ์ง ์ฒ๋ฆฌ์ ์คํจํ์ต๋๋ค."
|
| 421 |
+
|
| 422 |
+
# API ํธ์ถ ์ ํ๋ผ๋ฏธํฐ ๋ก๊น
(๋ฏผ๊ฐํ ์ ๋ณด ์ ์ธ)
|
| 423 |
+
logger.info(f"Calling API with bg_type: {bg_type}, quality_level: {quality_level}")
|
| 424 |
+
|
| 425 |
# API ํธ์ถ
|
| 426 |
result = api_check_password(
|
| 427 |
password, temp_path, bg_type, simple, studio, nature, indoor, special, jewelry, special_effects,
|
| 428 |
request_text, quality_level, aspect_ratio, output_format, enable_enhancement
|
| 429 |
)
|
| 430 |
return result
|
| 431 |
+
|
| 432 |
+
except Exception as e:
|
| 433 |
+
logger.error(f"Error in check_password wrapper: {e}")
|
| 434 |
+
logger.error(f"Full error: {traceback.format_exc()}")
|
| 435 |
+
return [], None, [], None, "", "", f"์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 436 |
+
|
| 437 |
finally:
|
| 438 |
# ์์ ํ์ผ ์ ๋ฆฌ
|
| 439 |
+
if temp_path and os.path.exists(temp_path):
|
| 440 |
try:
|
| 441 |
os.remove(temp_path)
|
| 442 |
+
logger.info(f"Cleaned up temporary file: {temp_path}")
|
| 443 |
+
except Exception as cleanup_error:
|
| 444 |
+
logger.warning(f"Failed to cleanup temp file {temp_path}: {cleanup_error}")
|
| 445 |
|
| 446 |
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ (์๋ณธ๊ณผ ๋์ผํ API ์ด๋ฆ)
|
| 447 |
generate_prompt_btn.click(
|