Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -70,22 +70,15 @@ async def generate_command(
|
|
70 |
image_url_or_error = await generate_image_async(prompt, aspect_ratio.value)
|
71 |
|
72 |
if image_url_or_error.startswith("http"):
|
73 |
-
# Download the image
|
74 |
-
async with aiohttp.ClientSession() as session:
|
75 |
-
async with session.get(image_url_or_error) as resp:
|
76 |
-
if resp.status != 200:
|
77 |
-
return await interaction.followup.send('Could not download file...')
|
78 |
-
image_data = await resp.read()
|
79 |
-
|
80 |
# Format the prompt for display with expand/collapse
|
81 |
formatted_prompt, initial_content, full_content = format_prompt_for_discord(prompt)
|
82 |
|
83 |
# Create buttons
|
84 |
async def show_more_callback(interaction):
|
85 |
-
await interaction.response.edit_message(content=full_content, view=view)
|
86 |
|
87 |
async def show_less_callback(interaction):
|
88 |
-
await interaction.response.edit_message(content=initial_content, view=view)
|
89 |
|
90 |
show_more_button = Button(label="Read More", style=discord.ButtonStyle.primary)
|
91 |
show_more_button.callback = show_more_callback
|
@@ -97,14 +90,10 @@ async def generate_command(
|
|
97 |
view.add_item(show_more_button)
|
98 |
view.add_item(show_less_button)
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
file=discord.File(image_file, 'generated_image.png'),
|
105 |
-
view=view
|
106 |
-
)
|
107 |
-
|
108 |
else:
|
109 |
await interaction.followup.send(
|
110 |
f"Sorry, I couldn't generate an image. {image_url_or_error}"
|
|
|
70 |
image_url_or_error = await generate_image_async(prompt, aspect_ratio.value)
|
71 |
|
72 |
if image_url_or_error.startswith("http"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
# Format the prompt for display with expand/collapse
|
74 |
formatted_prompt, initial_content, full_content = format_prompt_for_discord(prompt)
|
75 |
|
76 |
# Create buttons
|
77 |
async def show_more_callback(interaction):
|
78 |
+
await interaction.response.edit_message(content=f"{full_content}\n{image_url_or_error}", view=view)
|
79 |
|
80 |
async def show_less_callback(interaction):
|
81 |
+
await interaction.response.edit_message(content=f"{initial_content}\n{image_url_or_error}", view=view)
|
82 |
|
83 |
show_more_button = Button(label="Read More", style=discord.ButtonStyle.primary)
|
84 |
show_more_button.callback = show_more_callback
|
|
|
90 |
view.add_item(show_more_button)
|
91 |
view.add_item(show_less_button)
|
92 |
|
93 |
+
await interaction.followup.send(
|
94 |
+
f"{initial_content}\n{image_url_or_error}", # Include image URL initially
|
95 |
+
view=view
|
96 |
+
)
|
|
|
|
|
|
|
|
|
97 |
else:
|
98 |
await interaction.followup.send(
|
99 |
f"Sorry, I couldn't generate an image. {image_url_or_error}"
|