Holy shit, we did it, adding stable diffusion to dale bot. Depends on my windows computer being online and running it though
This commit is contained in:
parent
c2a5c0bbd9
commit
d510da4a5d
0
app/animals.py
Normal file → Executable file
0
app/animals.py
Normal file → Executable file
@ -66,6 +66,30 @@ class ActualUtils(commands.Cog):
|
||||
questions.open_ai(query),
|
||||
)
|
||||
|
||||
@commands.command(name="sd")
|
||||
async def sd(self, ctx: commands.Context, *, prompt):
|
||||
if ctx.message.author.id != 144986109804412928:
|
||||
await ctx.send("Sorry, this is a paid dale-bot feature")
|
||||
return
|
||||
|
||||
import stable_diffusion
|
||||
|
||||
try:
|
||||
ip = "192.168.1.188"
|
||||
port = "7860"
|
||||
file_path = stable_diffusion.generate_image(ip=ip, port=port, prompt=prompt)
|
||||
await ctx.reply(
|
||||
file=discord.File(
|
||||
file_path,
|
||||
filename="unknown.png",
|
||||
)
|
||||
)
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
await ctx.reply(
|
||||
"Stable diffusion isnt running right now, sorry.\n%s" % e,
|
||||
)
|
||||
|
||||
@commands.command(name="trackdays")
|
||||
async def trackdays(self, ctx: commands.Context):
|
||||
role = discord.utils.find(
|
||||
|
0
app/help_methods.py
Normal file → Executable file
0
app/help_methods.py
Normal file → Executable file
0
app/nft.py
Normal file → Executable file
0
app/nft.py
Normal file → Executable file
0
app/questions.py
Normal file → Executable file
0
app/questions.py
Normal file → Executable file
68
app/stable_diffusion.py
Executable file
68
app/stable_diffusion.py
Executable file
@ -0,0 +1,68 @@
|
||||
import base64
|
||||
import json
|
||||
import requests
|
||||
import socket
|
||||
import tempfile
|
||||
|
||||
|
||||
def generate_image(ip, port, prompt):
|
||||
url = "http://" + ip + ":" + port + "/api/predict/"
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:105.0) Gecko/20100101 Firefox/105.0",
|
||||
"Accept": "*/*",
|
||||
"Accept-Language": "en-US,en;q=0.5",
|
||||
"DNT": "1",
|
||||
"Connection": "keep-alive",
|
||||
}
|
||||
|
||||
json_data = {
|
||||
"fn_index": 11,
|
||||
"data": [
|
||||
prompt,
|
||||
"",
|
||||
"None",
|
||||
"None",
|
||||
20,
|
||||
"Euler a",
|
||||
False,
|
||||
False,
|
||||
1,
|
||||
1,
|
||||
7,
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
False,
|
||||
512,
|
||||
512,
|
||||
False,
|
||||
False,
|
||||
0.7,
|
||||
"None",
|
||||
False,
|
||||
False,
|
||||
None,
|
||||
"",
|
||||
"Seed",
|
||||
"",
|
||||
"Steps",
|
||||
"",
|
||||
True,
|
||||
False,
|
||||
None,
|
||||
"",
|
||||
"",
|
||||
],
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=json_data)
|
||||
imageb64 = response.json()["data"][0][0].split("data:image/png;base64,")[1]
|
||||
|
||||
imgdata = base64.b64decode(imageb64)
|
||||
file, file_path = tempfile.mkstemp()
|
||||
|
||||
with open(file_path, "wb") as f:
|
||||
f.write(imgdata)
|
||||
return file_path
|
Loading…
x
Reference in New Issue
Block a user