fix SD to use the latest api, but itll only work on my gaming computer for now

This commit is contained in:
Luke Robles 2023-09-14 09:05:25 -07:00
parent c5cbbc3205
commit d4ec0a9408
2 changed files with 19 additions and 62 deletions

View File

@ -35,25 +35,27 @@ class StableDiffusion(commands.Cog):
port = "7860" port = "7860"
ip = "192.168.1.80" ip = "192.168.1.80"
steps = 20 steps = 50
# Send my requests to my gaming computer with the 3080 (if its up) # Send my requests to my gaming computer with the 3080 (if its up)
if ctx.author.id == core_utils.my_id: if ctx.author.id == core_utils.my_id:
ip = "192.168.1.19" ip = "192.168.1.19"
steps = 90 positive_prompt = (
positive_prompt
+ " <lora:add_detail:0.3> <lora:bimbostyleThreeU:0.3> <lora:gigatitums:0.3> <lora:more_details:0.3>"
)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1) s.settimeout(1)
try: try:
s.connect((ip, int(port))) s.connect((ip, int(port)))
except: except:
ip = "192.168.1.80" ip = "192.168.1.80"
steps = 60
try: try:
await ctx.defer() await ctx.defer()
original_message = await ctx.followup.send( original_message = await ctx.followup.send(
"Please be patient, I'm generating your image" "Please be patient, I'm generating your image"
) )
file_path, time_taken = await stable_diffusion.generate_image( file_path = await stable_diffusion.generate_image(
ip=ip, ip=ip,
port=port, port=port,
positives=positive_prompt, positives=positive_prompt,
@ -62,7 +64,6 @@ class StableDiffusion(commands.Cog):
steps=steps, steps=steps,
) )
await original_message.edit( await original_message.edit(
content=time_taken,
file=discord.File( file=discord.File(
file_path, file_path,
filename="unknown.png", filename="unknown.png",

View File

@ -1,71 +1,27 @@
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import base64
import httpx import httpx
import tempfile import tempfile
async def generate_image(ip, port, positives, negatives, steps): async def generate_image(ip, port, positives, negatives, steps):
url = "http://" + ip + ":" + port + "/run/predict/" url = "http://" + ip + ":" + port + "/sdapi/v1/txt2img"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"DNT": "1",
"Connection": "keep-alive",
}
json_data = { json_data = {
"fn_index": 52, "prompt": positives,
"data": [ "negative_prompt": negatives,
positives, "steps": steps,
negatives, "hr_upscale": 2,
"None", "alwayson_scripts": {"ADetailer": {"args": [{"ad_model": "face_yolov8n.pt"}]}},
"None",
steps,
"Euler a",
True,
False,
1,
1,
7,
-1,
-1,
0,
0,
0,
False,
512,
512,
True,
0.7,
0,
0,
"None",
False,
False,
False,
False,
"",
"Seed",
"",
"Nothing",
"",
True,
False,
False,
None,
],
} }
client = httpx.AsyncClient()
response = await client.post(url, headers=headers, json=json_data, timeout=1200)
file_path = response.json()["data"][0][0]["name"]
imgdata = await client.get("http://%s:%s/file=%s" % (ip, port, file_path)) client = httpx.AsyncClient()
response = await client.post(url, json=json_data, timeout=1200)
b64_image = response.json()["images"][0]
file, file_path = tempfile.mkstemp() file, file_path = tempfile.mkstemp()
with open(file_path, "wb") as f: with open(file_path, "wb") as f:
f.write(imgdata.content) f.write(base64.b64decode(b64_image))
soup = BeautifulSoup(response.json()["data"][2], "html.parser") return file_path
time_taken = soup.find("p", class_="time").text
return file_path, time_taken