miaoshouai / miaoshouai-assistant

MiaoshouAI Assistant for Automatic1111 Webui
Apache License 2.0
314 stars 25 forks source link

Everytime i open auto1111 this happens #67

Open elen07zz opened 8 months ago

elen07zz commented 8 months ago

Why every time I open auto1111 does it reinstall all this? Installing Miaoshou assistant requirement: gpt_index==0.4.24 Installing Miaoshou assistant requirement: langchain==0.0.132 Installing Miaoshou assistant requirement: gradio_client==0.5.0 Installing Miaoshou assistant requirement: requests==2.31.0 Installing Miaoshou assistant requirement: urllib3==2.0.6 Installing Miaoshou assistant requirement: tqdm==4.64.0

Is there any way to avoid it?

Dadpoole commented 7 months ago

Came here to ask the same

crmbz0r commented 6 months ago

Open the file "install.py" located in your \extensions\miaoshouai-assistant folder, replace content with this:

import launch
import os
import gzip
import io
import shutil
import subprocess
import sys

def install_preset_models_if_needed():
    assets_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "assets")
    configs_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs")

    for model_filename in ["civitai_models.json", "liandange_models.json", "gpt_index.json"]:
        try:
            gzip_file = os.path.join(assets_folder, f"{model_filename}.gz")
            target_file = os.path.join(configs_folder, f"{model_filename}")
            if not os.path.exists(target_file):
                with gzip.open(gzip_file, "rb") as compressed_file:
                    with io.TextIOWrapper(compressed_file, encoding="utf-8") as decoder:
                        content = decoder.read()
                        with open(target_file, "w") as model_file:
                            model_file.write(content)
        except Exception as e:
            print(f"Failed to find or extract {model_filename} under assets directory: {e}")

req_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt")

def is_installed(lib):
    try:
        subprocess.check_call([sys.executable, "-m", "pip", "show", lib.split('==')[0]], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        return True
    except subprocess.CalledProcessError:
        return False

with open(req_file) as file:
    for lib in file:
        lib = lib.strip()
        if lib and not is_installed(lib):
            launch.run_pip(f"install {lib}", f"Miaoshou assistant requirement: {lib}")

install_preset_models_if_needed()
Dadpoole commented 6 months ago

Open the file "install.py" located in your \extensions\miaoshouai-assistant folder, replace content with this:

import launch
import os
import gzip
import io
import shutil
import subprocess
import sys

def install_preset_models_if_needed():
    assets_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "assets")
    configs_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs")

    for model_filename in ["civitai_models.json", "liandange_models.json", "gpt_index.json"]:
        try:
            gzip_file = os.path.join(assets_folder, f"{model_filename}.gz")
            target_file = os.path.join(configs_folder, f"{model_filename}")
            if not os.path.exists(target_file):
                with gzip.open(gzip_file, "rb") as compressed_file:
                    with io.TextIOWrapper(compressed_file, encoding="utf-8") as decoder:
                        content = decoder.read()
                        with open(target_file, "w") as model_file:
                            model_file.write(content)
        except Exception as e:
            print(f"Failed to find or extract {model_filename} under assets directory: {e}")

req_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt")

def is_installed(lib):
    try:
        subprocess.check_call([sys.executable, "-m", "pip", "show", lib.split('==')[0]], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        return True
    except subprocess.CalledProcessError:
        return False

with open(req_file) as file:
    for lib in file:
        lib = lib.strip()
        if lib and not is_installed(lib):
            launch.run_pip(f"install {lib}", f"Miaoshou assistant requirement: {lib}")

install_preset_models_if_needed()

This worked; those messages went away once the file was. Thank you very much!

Hujikuio commented 1 week ago

Still experiencing this on latest version. I am using reForge which I assume this extension would still be the correct version as it's not on Gradio 4, correct? @miaoshouai

I just checked and it seems like the latest 1.9 commit/release has re-added the offending lines