Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ load_dotenv()
|
|
15 |
DISCORD_TOKEN = os.getenv('dsTOK')
|
16 |
HF_API_KEY = os.getenv('HFREAD')
|
17 |
|
18 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
19 |
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
20 |
|
21 |
# Set up logging
|
@@ -45,7 +45,7 @@ async def on_ready():
|
|
45 |
|
46 |
@bot.command(name='generate')
|
47 |
@commands.cooldown(rate=1, per=10, type=commands.BucketType.user)
|
48 |
-
async def generate(ctx,
|
49 |
"""
|
50 |
Command to generate an image based on a description using the Hugging Face model.
|
51 |
"""
|
@@ -53,18 +53,17 @@ async def generate(ctx, *, description: str):
|
|
53 |
await ctx.send("You need to provide a description for the image.")
|
54 |
return
|
55 |
|
|
|
56 |
try:
|
57 |
payload = {"inputs": description}
|
58 |
image_bytes = query(payload)
|
59 |
|
60 |
if image_bytes:
|
61 |
image = Image.open(io.BytesIO(image_bytes))
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
await ctx.send("Here is your generated image:", file=picture)
|
67 |
-
os.remove(image_path) # Clean up the file after sending
|
68 |
else:
|
69 |
await ctx.send("An error occurred while generating the image.")
|
70 |
except Exception as e:
|
|
|
15 |
DISCORD_TOKEN = os.getenv('dsTOK')
|
16 |
HF_API_KEY = os.getenv('HFREAD')
|
17 |
|
18 |
+
API_URL = "https://api-inference.huggingface.co/models/Corcelio/mobius"
|
19 |
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
20 |
|
21 |
# Set up logging
|
|
|
45 |
|
46 |
@bot.command(name='generate')
|
47 |
@commands.cooldown(rate=1, per=10, type=commands.BucketType.user)
|
48 |
+
async def generate(ctx, *description):
|
49 |
"""
|
50 |
Command to generate an image based on a description using the Hugging Face model.
|
51 |
"""
|
|
|
53 |
await ctx.send("You need to provide a description for the image.")
|
54 |
return
|
55 |
|
56 |
+
description = " ".join(description)
|
57 |
try:
|
58 |
payload = {"inputs": description}
|
59 |
image_bytes = query(payload)
|
60 |
|
61 |
if image_bytes:
|
62 |
image = Image.open(io.BytesIO(image_bytes))
|
63 |
+
with io.BytesIO() as image_binary:
|
64 |
+
image.save(image_binary, 'PNG')
|
65 |
+
image_binary.seek(0)
|
66 |
+
await ctx.send(file=discord.File(fp=image_binary, filename='generated_image.png'))
|
|
|
|
|
67 |
else:
|
68 |
await ctx.send("An error occurred while generating the image.")
|
69 |
except Exception as e:
|