Kilvoctu / aiyabot

A neat Discord bot for AUTOMATIC1111's Web UI
GNU General Public License v2.0
309 stars 76 forks source link

LoRAs or High-res unaccessable when using gradio-auth #235

Closed sebaxakerhtc closed 7 months ago

sebaxakerhtc commented 7 months ago

Describe the bug
When using --gradio-auth we get message "Trouble accessing Web UI config! I can't pull the LoRAs or High-res upscaler lists!" The problem is inside settings.py

    config_url = s.get(global_var.url + "/config")
    old_config = config_url.json()
    try:
        for c in old_config['components']:
            try:
                if c['props']:
                    if c['props']['elem_id'] == 'setting_sd_lora':
                        global_var.lora_names = c['props']['choices']
                    if c['props']['elem_id'] == 'txt2img_hr_upscaler':
                        global_var.hires_upscaler_names = c['props']['choices']
            except(Exception,):
                pass
    except(Exception,):
        print("Trouble accessing Web UI config! I can't pull the LoRAs or High-res upscaler lists!")

For solving this problem I added a part from begining:

    login_payload = {
        'username': global_var.username,
        'password': global_var.password
    }
    s.post(global_var.url + '/login', data=login_payload)

This solve the problem, but I think it should use the same code from begining of file. I tried call the function authenticate_user(), but with no luck. For now this code works:

    # iterate through config for anything unobtainable from API
    login_payload = {
        'username': global_var.username,
        'password': global_var.password
    }
    s.post(global_var.url + '/login', data=login_payload)
    config_url = s.get(global_var.url + "/config")
    old_config = config_url.json()
    try:
        for c in old_config['components']:
            try:
                if c['props']:
                    if c['props']['elem_id'] == 'setting_sd_lora':
                        global_var.lora_names = c['props']['choices']
                    if c['props']['elem_id'] == 'txt2img_hr_upscaler':
                        global_var.hires_upscaler_names = c['props']['choices']
            except(Exception,):
                pass
    except(Exception,):
        print("Trouble accessing Web UI config! I can't pull the LoRAs or High-res upscaler lists!")

Environment


Console logs

Trouble accessing Web UI config! I can't pull the LoRAs or High-res upscaler lists!
Kilvoctu commented 7 months ago

I don't know when it was changed, but /sdapi/v1/cmd-flags can be accessed without authentication or something (it returns status code 200), which is how I did my gradio-auth check. As a result global_var.gradio_auth was never set to True. I just changed it to verify with /config instead, which works for now.