artintel235 commited on
Commit
b0d3fa7
·
verified ·
1 Parent(s): d3c6432

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -22
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
- if not image_url_or_error.startswith("http"):
91
- await interaction.followup.send(f"Sorry, I couldn't generate an image: {image_url_or_error}")
92
- return
93
-
94
- # Download the image
95
- async with aiohttp.ClientSession() as session:
96
- async with session.get(image_url_or_error) as image_response:
97
- image_response.raise_for_status()
98
- image_data = await image_response.read()
99
-
100
- # Prepare the file-like object
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: {str(e)}")
 
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):