Wildric-Auric / MidJourney-Wrapper

MidJourney wrapper in Discord.
Creative Commons Zero v1.0 Universal
695 stars 149 forks source link

Upscale and Variation don't work #5

Closed kuyin closed 1 year ago

kuyin commented 1 year ago

I wanna learn from this code. Imagine works well. But upscale and variation don't work how to fix this bro?

Wildric-Auric commented 1 year ago

Like you have seen in the last issue, a hashed string has been added to the request which didn't exist before. For now there is no solution found. As soon as It will be found I will implement it in the code.

kuyin commented 1 year ago

Thanks for your reply! Wating for your good news!

------------------ 原始邮件 ------------------ 发件人: "Wildric-Auric/MidJourney-Wrapper" @.>; 发送时间: 2022年11月2日(星期三) 晚上8:20 @.>; @.**@.>; 主题: Re: [Wildric-Auric/MidJourney-Wrapper] Upscale and Variation don't work (Issue #5)

Like you have seen in the last issue, a hashed string has been added to the request which didn't exist before. For now there is no solution found. As soon as It will be found I will implement it in the code.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

iandwalsh commented 1 year ago

thought i'd share how i solved the upscale and variation. im posting fragments of bits of code to get something out for ya folks since it's been a few days. hopefully my method makes sense. please note what i pasted is no where near complete, i was simply pulling the bits from my edits to put something out there.

############# main.py
import re

@bot.event
async def on_message_edit(before, after):

    if image_url == "": return
    image_uuid = re.findall("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",baction)[0]

    image_percent = find_between(image_url, "progress_image_", "_")
    image_buffer(after, image_uuid, image_percent, image_url)

def image_buffer(image_content, image_uuid, image_percent, image_url):
    temp_array = {
        "percent": int(image_percent),
        "url": str(image_url)
    }

    try:
        value = image_array[str(image_uuid)]
    except KeyError:
        # Key is not present
        image_array[str(image_uuid)] = {}

    image_array[str(image_uuid)]["image_data"]["renders"].append(temp_array)

basically, on the on_message_edit (where the bot iterates through the cycles to render) the image URLS contain the UUID. I simply extract it, check if im storing it, if not, save it. once its done, i check the message contents of the final image thats generated to get list of what buttons (upscale/variations) exist, then i generate the full custom id reference.

then i only need to call one function, and i can skip having to do the $mj_target altogether as well since im storing the final message id of the image, as well as a list of all the actions.

###################### Salai.py
def Action(messageId : str, button_action : str):
    button = button_action
    payload = {"type":3,
    "guild_id":Globals.SERVER_ID,
    "channel_id":Globals.CHANNEL_ID,
    "message_flags":0,
    "message_id": messageId,
    "application_id":"936929561302675456",
    "session_id":"45bc04dd4***********",
    "data":{"component_type":2,
            "custom_id":str(button)}
        }  
    header = {
        'authorization' : Globals.SALAI_TOKEN
    }
    response = requests.post("https://discord.com/api/v9/interactions",
    json = payload, headers = header)
    return response

i end up with this per image that i can easily utilize without the extra manually reply to message

Midjourney Bot#1234 (9********561234556) CREATED message: 89946846842222
https://cdn.discordapp.com/attachments/xxxxxxxxxxxxxx/xxxxxxxxxx/DiscordName_lorem_ipsum_dolar_dolla_bill_ya_12345678-abcd-a1b2c3sdf.png
MJ::JOB::upsample::1::12345678-abcd-a1b2c3sdf
MJ::JOB::upsample::2::12345678-abcd-a1b2c3sdf
MJ::JOB::upsample::3::12345678-abcd-a1b2c3sdf
MJ::JOB::upsample::4::12345678-abcd-a1b2c3sdf
MJ::JOB::reroll::0::12345678-abcd-a1b2c3sdf::SOLO
MJ::JOB::variation::1::12345678-abcd-a1b2c3sdf
MJ::JOB::variation::2::12345678-abcd-a1b2c3sdf
MJ::JOB::variation::3::12345678-abcd-a1b2c3sdf
MJ::JOB::variation::4::12345678-abcd-a1b2c3sdf

didn't proof read, and again, just wanted to help in case this gets people somewhere in the meantime until a more acceptable solution is provided.

cheers!

Wildric-Auric commented 1 year ago

I didn't notice the that the hash was in me the url; thank you. The issue will be closed as soon as the soltution will be implmented and tested.

Wildric-Auric commented 1 year ago

Fixed