Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -60,7 +60,6 @@ async def generate_image_async(prompt, aspect_ratio):
|
|
60 |
except aiohttp.ClientError as e:
|
61 |
return f"API request failed: {e}"
|
62 |
|
63 |
-
# --- Discord Slash Commands ---
|
64 |
@tree.command(
|
65 |
name="generate", description="Generates an image based on a text prompt"
|
66 |
)
|
@@ -80,29 +79,27 @@ async def generate_command(
|
|
80 |
prompt: str,
|
81 |
aspect_ratio: app_commands.Choice[str],
|
82 |
):
|
|
|
83 |
try:
|
84 |
await interaction.response.defer() # MUST be the first await
|
85 |
|
86 |
-
#
|
87 |
-
|
88 |
-
|
89 |
-
"""Generates an image based on the user's prompt and aspect ratio."""
|
90 |
-
# await interaction.response.defer() # Acknowledge within 3 seconds
|
91 |
-
|
92 |
-
# Call the asynchronous image generation function
|
93 |
-
image_url_or_error = await generate_image_async(
|
94 |
-
prompt, aspect_ratio.value
|
95 |
-
)
|
96 |
-
|
97 |
-
if image_url_or_error.startswith("http"):
|
98 |
-
await interaction.followup.send(
|
99 |
-
f"Here's your generated image based on the prompt '{prompt}' with aspect ratio {aspect_ratio.name}:\n{image_url_or_error}"
|
100 |
-
)
|
101 |
-
else:
|
102 |
-
await interaction.followup.send(
|
103 |
-
f"Sorry, I couldn't generate an image. {image_url_or_error}"
|
104 |
)
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
@tree.command(name="hello", description="Says hello!")
|
107 |
async def hello_command(interaction):
|
108 |
await interaction.response.send_message("Hello there!")
|
|
|
60 |
except aiohttp.ClientError as e:
|
61 |
return f"API request failed: {e}"
|
62 |
|
|
|
63 |
@tree.command(
|
64 |
name="generate", description="Generates an image based on a text prompt"
|
65 |
)
|
|
|
79 |
prompt: str,
|
80 |
aspect_ratio: app_commands.Choice[str],
|
81 |
):
|
82 |
+
"""Generates an image based on the user's prompt and aspect ratio."""
|
83 |
try:
|
84 |
await interaction.response.defer() # MUST be the first await
|
85 |
|
86 |
+
# Now it's safe to make other async calls:
|
87 |
+
image_url_or_error = await generate_image_async(
|
88 |
+
prompt, aspect_ratio.value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
)
|
90 |
|
91 |
+
if image_url_or_error.startswith("http"):
|
92 |
+
await interaction.followup.send(
|
93 |
+
f"Here's your generated image based on the prompt '{prompt}' with aspect ratio {aspect_ratio.name}:\n{image_url_or_error}"
|
94 |
+
)
|
95 |
+
else:
|
96 |
+
await interaction.followup.send(
|
97 |
+
f"Sorry, I couldn't generate an image. {image_url_or_error}"
|
98 |
+
)
|
99 |
+
|
100 |
+
except Exception as e:
|
101 |
+
print(f"An error occurred: {e}")
|
102 |
+
await interaction.followup.send("An error occurred while processing your request.")
|
103 |
@tree.command(name="hello", description="Says hello!")
|
104 |
async def hello_command(interaction):
|
105 |
await interaction.response.send_message("Hello there!")
|