seawolf2357 commited on
Commit
a2fb30b
Β·
verified Β·
1 Parent(s): 49c60e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -36,10 +36,12 @@ class MyClient(discord.Client):
36
  self.is_processing = True
37
  try:
38
  prompt = message.content[len('!image '):]
39
- image_path = await self.generate_image(prompt)
40
  user_id = message.author.id
41
  await message.channel.send(
42
- f"<@{user_id}> λ‹˜μ΄ μš”μ²­ν•˜μ‹  μ΄λ―Έμ§€μž…λ‹ˆλ‹€.",
 
 
43
  file=discord.File(image_path)
44
  )
45
  # 이미지 생성 ν›„ μ„€λͺ… 제곡 및 λŒ€ν™”
@@ -48,7 +50,8 @@ class MyClient(discord.Client):
48
  logging.error(f'이미지 생성 쀑 였λ₯˜ λ°œμƒ: {e}')
49
  await message.channel.send("이미지 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. λ‚˜μ€‘μ— λ‹€μ‹œ μ‹œλ„ν•΄ μ£Όμ„Έμš”.")
50
  finally:
51
- self.is_processing = False
 
52
 
53
  async def generate_image(self, prompt):
54
  if not prompt:
@@ -68,14 +71,21 @@ class MyClient(discord.Client):
68
  api_name="/infer_t2i"
69
  )
70
  logging.debug(f"API response received: {result}")
 
 
 
 
 
 
71
 
72
- # API μ‘λ‹΅μ—μ„œ 이미지 파일 경둜 μΆ”μΆœ
73
- image_path = result[0] # API 응닡 ꡬ쑰에 따라 쑰정이 ν•„μš”ν•  수 μžˆμŠ΅λ‹ˆλ‹€
74
-
75
- return image_path
76
  except Exception as e:
77
- logging.error(f'API μš”μ²­ 쀑 였λ₯˜ λ°œμƒ: {e}')
78
  raise RuntimeError(f"API μš”μ²­ 쀑 였λ₯˜ λ°œμƒ: {str(e)}")
 
 
79
 
80
  async def initiate_conversation(prompt, message):
81
  logging.debug(f'λŒ€ν™” μ‹œμž‘ 쀑: {prompt}')
 
36
  self.is_processing = True
37
  try:
38
  prompt = message.content[len('!image '):]
39
+ image_path, used_seed, translated_prompt = await self.generate_image(prompt)
40
  user_id = message.author.id
41
  await message.channel.send(
42
+ f"<@{user_id}> λ‹˜μ΄ μš”μ²­ν•˜μ‹  μ΄λ―Έμ§€μž…λ‹ˆλ‹€.\n"
43
+ f"μ‚¬μš©λœ μ‹œλ“œ: {used_seed}\n"
44
+ f"λ²ˆμ—­λœ ν”„λ‘¬ν”„νŠΈ: {translated_prompt}",
45
  file=discord.File(image_path)
46
  )
47
  # 이미지 생성 ν›„ μ„€λͺ… 제곡 및 λŒ€ν™”
 
50
  logging.error(f'이미지 생성 쀑 였λ₯˜ λ°œμƒ: {e}')
51
  await message.channel.send("이미지 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. λ‚˜μ€‘μ— λ‹€μ‹œ μ‹œλ„ν•΄ μ£Όμ„Έμš”.")
52
  finally:
53
+ self.is_processing = False
54
+
55
 
56
  async def generate_image(self, prompt):
57
  if not prompt:
 
71
  api_name="/infer_t2i"
72
  )
73
  logging.debug(f"API response received: {result}")
74
+
75
+ if isinstance(result, tuple) and len(result) == 3:
76
+ image_path, used_seed, translated_prompt = result
77
+ logging.info(f"Image generated at: {image_path}")
78
+ logging.info(f"Used seed: {used_seed}")
79
+ logging.info(f"Translated prompt: {translated_prompt}")
80
 
81
+ return image_path, used_seed, translated_prompt
82
+ else:
83
+ raise ValueError("Unexpected API response format")
 
84
  except Exception as e:
85
+ logging.error(f'API μš”μ²­ 쀑 였λ₯˜ λ°œμƒ: {e}', exc_info=True)
86
  raise RuntimeError(f"API μš”μ²­ 쀑 였λ₯˜ λ°œμƒ: {str(e)}")
87
+
88
+
89
 
90
  async def initiate_conversation(prompt, message):
91
  logging.debug(f'λŒ€ν™” μ‹œμž‘ 쀑: {prompt}')