-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbot.py
73 lines (65 loc) · 2.68 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from fileinput import filename
import discord
from discord import Intents
from discord.ext import commands
from dotenv import load_dotenv
from PIL import Image
import warnings
import os
import io
from stability_sdk import client
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
load_dotenv()
stability_api = client.StabilityInference(
key=os.environ['STABLE_DIFFUSION_TOKEN'],
verbose=True,
)
intents = Intents.default()
intents.message_content = True
bot = commands.Bot(
command_prefix="!",
description="Make art.",
intents=intents,
)
@bot.command()
async def dream(ctx, *, prompt):
msg = await ctx.send(f"“{prompt}”\n> Generating...")
answers = stability_api.generate(prompt=prompt)
for resp in answers:
for artifact in resp.artifacts:
if artifact.finish_reason == generation.FILTER:
warnings.warn(
"Your request activated the API's safety filters and could not be processed."
"Please modify the prompt and try again.")
msg = await ctx.send(
"You have triggered the filter, please try again")
if artifact.type == generation.ARTIFACT_IMAGE:
img = Image.open(io.BytesIO(artifact.binary))
arr = io.BytesIO(artifact.binary)
img.save(arr, format='PNG')
arr.seek(0)
file = discord.File(arr, filename='art.png')
await msg.edit(content=f"“{prompt}” \n")
await ctx.send(file=file)
## This command will generate AI art for a specific dimension. I chose 738 x 251 for my purposes
@bot.command()
async def load(ctx, *, prompt):
msg = await ctx.send(f"“{prompt}”\n> Generating...")
answers = stability_api.generate(prompt=prompt, width=1472, height= 512)
for resp in answers:
for artifact in resp.artifacts:
if artifact.finish_reason == generation.FILTER:
warnings.warn(
"Your request activated the API's safety filters and could not be processed."
"Please modify the prompt and try again.")
msg = await ctx.send(
"You have triggered the filter, please try again")
if artifact.type == generation.ARTIFACT_IMAGE:
img = Image.open(io.BytesIO(artifact.binary))
arr = io.BytesIO(artifact.binary)
img.save(arr, format='PNG')
arr.seek(0)
file = discord.File(arr, filename='art.png')
await msg.edit(content=f"“{prompt}” \n")
await ctx.send(file=file)
bot.run(os.environ["DISCORD_TOKEN"])