Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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μ
λλ€")
|