Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import requests
|
|
5 |
import asyncio
|
6 |
import aiohttp # Use aiohttp for asynchronous HTTP requests
|
7 |
import gradio as gr # Import Gradio
|
8 |
-
from io import BytesIO
|
9 |
|
10 |
# --- Environment Variables & Setup ---
|
11 |
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
|
@@ -85,29 +84,21 @@ async def generate_command(
|
|
85 |
try:
|
86 |
await interaction.response.defer()
|
87 |
|
88 |
-
# Fetch the URL of the image
|
89 |
image_url_or_error = await generate_image_async(prompt, aspect_ratio.value)
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
file = discord.File(BytesIO(image_data), filename="generated_image.png")
|
102 |
-
|
103 |
-
# Send the image as an attachment
|
104 |
-
await interaction.followup.send(
|
105 |
-
f"Here's your generated image based on the prompt '{prompt}' with aspect ratio {aspect_ratio.name}:",
|
106 |
-
file=file
|
107 |
-
)
|
108 |
-
|
109 |
except Exception as e:
|
110 |
-
await interaction.followup.send(f"Error
|
|
|
111 |
|
112 |
@tree.command(name="hello", description="Says hello!")
|
113 |
async def hello_command(interaction):
|
|
|
5 |
import asyncio
|
6 |
import aiohttp # Use aiohttp for asynchronous HTTP requests
|
7 |
import gradio as gr # Import Gradio
|
|
|
8 |
|
9 |
# --- Environment Variables & Setup ---
|
10 |
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
|
|
|
84 |
try:
|
85 |
await interaction.response.defer()
|
86 |
|
|
|
87 |
image_url_or_error = await generate_image_async(prompt, aspect_ratio.value)
|
88 |
+
# await interaction.response.send_message(f"Error:{image_url_or_error}")
|
89 |
+
if image_url_or_error:
|
90 |
+
# if image_url_or_error.startswith("http"):
|
91 |
+
await interaction.followup.send(
|
92 |
+
# f"Here's your generated image based on the prompt '{prompt}' with aspect ratio {aspect_ratio.name}:\n{image_url_or_error}"
|
93 |
+
f"{image_url_or_error}"
|
94 |
+
)
|
95 |
+
else:
|
96 |
+
await interaction.followup.send(
|
97 |
+
f"Sorry, I couldn't generate an image"
|
98 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
except Exception as e:
|
100 |
+
await interaction.followup.send(f"Error")
|
101 |
+
|
102 |
|
103 |
@tree.command(name="hello", description="Says hello!")
|
104 |
async def hello_command(interaction):
|