ssboost commited on
Commit
0d2a59a
ยท
verified ยท
1 Parent(s): 644a519

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -9
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=image_file,
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
- except:
416
- pass
 
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(