Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 73 |
-
|
| 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}')
|