seawolf2357 commited on
Commit
7a21c4b
Β·
verified Β·
1 Parent(s): c40c235

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -24
app.py CHANGED
@@ -39,31 +39,39 @@ class MyClient(discord.Client):
39
  async def on_message(self, message):
40
  if message.author == self.user:
41
  return
42
- if message.content.startswith('!image '):
43
- if self.is_processing:
44
- await message.channel.send("이미지 생성이 이미 μ§„ν–‰ μ€‘μž…λ‹ˆλ‹€. μž μ‹œλ§Œ κΈ°λ‹€λ € μ£Όμ„Έμš”.")
45
- return
46
- self.is_processing = True
47
- try:
48
- prompt = message.content[len('!image '):]
49
- image_path, used_seed, translated_prompt = await self.generate_image(prompt)
50
- user_id = message.author.id
51
- await message.channel.send(
52
- f"<@{user_id}> λ‹˜μ΄ μš”μ²­ν•˜μ‹  μ΄λ―Έμ§€μž…λ‹ˆλ‹€.\n"
53
- f"μ‚¬μš©λœ μ‹œλ“œ: {used_seed}\n"
54
- f"λ²ˆμ—­λœ ν”„λ‘¬ν”„νŠΈ: {translated_prompt}",
55
- file=discord.File(image_path)
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μž…λ‹ˆλ‹€")
 
39
  async def on_message(self, message):
40
  if message.author == self.user:
41
  return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ # λ©”μ‹œμ§€μ—μ„œ '!'λ₯Ό κΈ°μ€€μœΌλ‘œ λͺ…령어와 ν”„λ‘¬ν”„νŠΈ 뢄리
44
+ if message.content.startswith('!'):
45
+ command, *prompt_parts = message.content.split(' ')
46
+ prompt = ' '.join(prompt_parts)
47
+ else:
48
+ prompt = message.content # λͺ…λ Ήμ–΄ 없이 ν”„λ‘¬ν”„νŠΈλ§Œ 있으면 κ·ΈλŒ€λ‘œ μ‚¬μš©
49
+
50
+ if self.is_processing:
51
+ await message.channel.send("이미지 생성이 이미 μ§„ν–‰ μ€‘μž…λ‹ˆλ‹€. μž μ‹œλ§Œ κΈ°λ‹€λ € μ£Όμ„Έμš”.")
52
+ return
53
+
54
+ self.is_processing = True
55
+ try:
56
+ image_path, used_seed, translated_prompt = await self.generate_image(prompt)
57
+ user_id = message.author.id
58
+ await message.channel.send(
59
+ f"<@{user_id}> λ‹˜μ΄ μš”μ²­ν•˜μ‹  μ΄λ―Έμ§€μž…λ‹ˆλ‹€.\n"
60
+ f"μ‚¬μš©λœ μ‹œλ“œ: {used_seed}\n"
61
+ f"λ²ˆμ—­λœ ν”„λ‘¬ν”„νŠΈ: {translated_prompt}",
62
+ file=discord.File(image_path)
63
+ )
64
+ # 이미지 생성 ν›„ μ„€λͺ… 제곡 및 λŒ€ν™”
65
+ await initiate_conversation(prompt, message)
66
+ except RuntimeError as e:
67
+ await message.channel.send(f"이미지 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}")
68
+ except Exception as e:
69
+ logging.error(f'이미지 생성 쀑 μ˜ˆμƒμΉ˜ λͺ»ν•œ 였λ₯˜ λ°œμƒ: {e}')
70
+ await message.channel.send("이미지 생성 쀑 μ˜ˆμƒμΉ˜ λͺ»ν•œ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. λ‚˜μ€‘μ— λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”.")
71
+ finally:
72
+ self.is_processing = False
73
+
74
+
75
  async def generate_image(self, prompt):
76
  if not prompt:
77
  raise ValueError("ν”„λ‘¬ν”„νŠΈκ°€ λΉ„μ–΄μžˆκ±°λ‚˜ Noneμž…λ‹ˆλ‹€")