Hello there! I've been thoroughly enjoying the base-template of your Bot which I've sort of completely re-shaped to my will. But there's just one thing that I'm really struggling to put into place and I was wondering if I could have your help..
The upscale function, I want it to do an hires-fix instead that I tune to my will:
"hr_scale": 1.35,
"hr_upscaler": "4x_NMKD-Superscale-SP_178000_G",
"denoising_strength": 0.35,```
Issue is, I do not know how to make it work with the current base of the bot.
async def imagegen(prompt, orientation, negative_prompt, variation=False):
print(orientation) # debug print statement
global total_requests
total_requests = total_requests + 1
global webui_url
global variation_strength
currentTime = datetime.now()
width, height = make_orientation(orientation)
with open('gen_settings.json') as json_file:
data = json.load(json_file)
default = data["default"]
enable_hr_value = data["enable_hr"]
hr_scale_value = data["hr_scale"]
hr_upscaler_value = data["hr_upscaler"]
hr_denoise_value = data["denoising_strength"]
add_prompt_txt = data["add_prompt"]
if variation:
variation_strength = variation_strength
else:
variation_strength = 0
config = load_config("gen_settings.json")
payload = {
"prompt": prompt + add_prompt_txt,
"negative_prompt" : negative_prompt,
"width": width,
"height": height,
"enable_hr": enable_hr_value,
"hr_scale": hr_scale_value,
"hr_upscaler": hr_upscaler_value,
"denoising_strength": hr_denoise_value,
"subseed_strength": variation_strength,
**config # Merge the loaded config with the payload
}
async with session.post(url=f'{webui_url}/sdapi/v1/txt2img', json=payload) as response:
r = await response.json()
for i in r['images']:
image = Image.open(io.BytesIO(base64.b64decode(i.split(",",1)[0])))
png_payload = {
"image": "data:image/png;base64," + i
}
async with session.post(url=f'{webui_url}/sdapi/v1/png-info', json=png_payload) as response2:
json_response = await response2.json()
pnginfo = PngImagePlugin.PngInfo()
pnginfo.add_text("parameters", json_response.get("info"))
global characters
image_id = ''.join(random.choice(characters) for i in range(24))
file_path = f"GeneratedImages/{image_id}.png"
image.save(file_path, pnginfo=pnginfo)
print ("Generated Image:", file_path)
print (total_requests)
with open('current_requests.txt', 'w') as file:
file.write(str(total_requests))
return file_path, image_id
Sends the upscale request to A1111
async def upscale(image):
global total_requests
total_requests = total_requests + 1
with open(image, 'rb') as image_file:
image_b64 = base64.b64encode(image_file.read()).decode()
upscale_payload = {
"upscaling_resize": 2,
"upscaling_crop": True,
"gfpgan_visibility": 0,
"codeformer_visibility": 0,
"codeformer_weight": 0,
"upscaler_1": "4x_NMKD-Siax_200k",
"image": image_b64
}
async with session.post(url=f'{webui_url}/sdapi/v1/extra-single-image', json=upscale_payload) as response_upscaled:
r_u = await response_upscaled.json()
image_bytes = base64.b64decode(r_u['image'])
image_upscaled = Image.open(io.BytesIO(image_bytes))
file_path = image
file_path = file_path.replace('.png', '')
file_path = f"{file_path}-upscaled.png"
image_upscaled.save(file_path)
print ("Upscaled Image:", file_path)
print (total_requests)
with open('current_requests.txt', 'w') as file:
file.write(str(total_requests))
return file_path
```
I'd just appreciate it to have the very bare minimum of help with this. Just the foundation, would help greatly. THanks in advance.
Also great work !