seawolf2357 commited on
Commit
8ca1e9d
Β·
verified Β·
1 Parent(s): 2949006

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -3,7 +3,9 @@ import logging
3
  import os
4
  from io import BytesIO
5
  from gradio_client import Client
 
6
  import subprocess
 
7
  # λ‘œκΉ… μ„€μ •
8
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
9
 
@@ -54,17 +56,19 @@ class MyClient(discord.Client):
54
  )
55
  # 이미지 생성 ν›„ μ„€λͺ… 제곡 및 λŒ€ν™”
56
  await initiate_conversation(prompt, message)
 
 
57
  except Exception as e:
58
- logging.error(f'이미지 생성 쀑 였λ₯˜ λ°œμƒ: {e}')
59
- await message.channel.send("μ‚¬μš© μ˜ˆμ‹œ: !image 고양이가 'HAPPY WORLD'라고 μ“°μ—¬μ§„ ν‘œμ§€νŒμ„ λ“€κ³ μžˆλ‹€. ")
60
  finally:
61
  self.is_processing = False
62
 
63
  async def generate_image(self, prompt):
64
  if not prompt:
65
- raise ValueError("Prompt is empty or None")
66
 
67
- logging.debug(f"Sending request to API with prompt: {prompt}")
68
 
69
  try:
70
  result = api_client.predict(
@@ -77,19 +81,19 @@ class MyClient(discord.Client):
77
  num_inference_steps=28,
78
  api_name="/infer_t2i"
79
  )
80
- logging.debug(f"API response received: {result}")
81
 
82
  if isinstance(result, tuple) and len(result) == 3:
83
  image_path, used_seed, translated_prompt = result
84
- logging.info(f"Image generated at: {image_path}")
85
- logging.info(f"Used seed: {used_seed}")
86
- logging.info(f"Translated prompt: {translated_prompt}")
87
 
88
  return image_path, used_seed, translated_prompt
89
  else:
90
- raise ValueError("Unexpected API response format")
91
- except gradio_client.exceptions.AppError as e:
92
- logging.error(f"Gradio App Error: {e}")
93
  raise RuntimeError(f"API μ„œλ²„ 였λ₯˜: {str(e)}. μ„œλ²„ κ΄€λ¦¬μžμ—κ²Œ λ¬Έμ˜ν•˜μ„Έμš”.")
94
  except Exception as e:
95
  logging.error(f'API μš”μ²­ 쀑 였λ₯˜ λ°œμƒ: {e}', exc_info=True)
 
3
  import os
4
  from io import BytesIO
5
  from gradio_client import Client
6
+ from gradio_client import exceptions as gradio_client_exceptions
7
  import subprocess
8
+
9
  # λ‘œκΉ… μ„€μ •
10
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
11
 
 
56
  )
57
  # 이미지 생성 ν›„ μ„€λͺ… 제곡 및 λŒ€ν™”
58
  await initiate_conversation(prompt, message)
59
+ except RuntimeError as e:
60
+ await message.channel.send(f"이미지 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}")
61
  except Exception as e:
62
+ logging.error(f'이미지 생성 쀑 μ˜ˆμƒμΉ˜ λͺ»ν•œ 였λ₯˜ λ°œμƒ: {e}')
63
+ await message.channel.send("이미지 생성 쀑 μ˜ˆμƒμΉ˜ λͺ»ν•œ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. λ‚˜μ€‘μ— λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”.")
64
  finally:
65
  self.is_processing = False
66
 
67
  async def generate_image(self, prompt):
68
  if not prompt:
69
+ raise ValueError("ν”„λ‘¬ν”„νŠΈκ°€ λΉ„μ–΄μžˆκ±°λ‚˜ Noneμž…λ‹ˆλ‹€")
70
 
71
+ logging.debug(f"API에 μš”μ²­ 전솑 쀑. ν”„λ‘¬ν”„νŠΈ: {prompt}")
72
 
73
  try:
74
  result = api_client.predict(
 
81
  num_inference_steps=28,
82
  api_name="/infer_t2i"
83
  )
84
+ logging.debug(f"API 응닡 μˆ˜μ‹ : {result}")
85
 
86
  if isinstance(result, tuple) and len(result) == 3:
87
  image_path, used_seed, translated_prompt = result
88
+ logging.info(f"μƒμ„±λœ 이미지 경둜: {image_path}")
89
+ logging.info(f"μ‚¬μš©λœ μ‹œλ“œ: {used_seed}")
90
+ logging.info(f"λ²ˆμ—­λœ ν”„λ‘¬ν”„νŠΈ: {translated_prompt}")
91
 
92
  return image_path, used_seed, translated_prompt
93
  else:
94
+ raise ValueError("μ˜ˆμƒμΉ˜ λͺ»ν•œ API 응닡 ν˜•μ‹")
95
+ except gradio_client_exceptions.AppError as e:
96
+ logging.error(f"Gradio μ•± 였λ₯˜: {e}")
97
  raise RuntimeError(f"API μ„œλ²„ 였λ₯˜: {str(e)}. μ„œλ²„ κ΄€λ¦¬μžμ—κ²Œ λ¬Έμ˜ν•˜μ„Έμš”.")
98
  except Exception as e:
99
  logging.error(f'API μš”μ²­ 쀑 였λ₯˜ λ°œμƒ: {e}', exc_info=True)