mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-01-16 19:28:18 -05:00
Compare commits
12 Commits
v3.0.1post
...
feat/trans
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ded521b019 | ||
|
|
a3980cc756 | ||
|
|
6f15a67592 | ||
|
|
a597b4bfaf | ||
|
|
6ac4338f00 | ||
|
|
eb642653cb | ||
|
|
f4ead5e07f | ||
|
|
6d24ca7f52 | ||
|
|
2164da8592 | ||
|
|
ba817b5648 | ||
|
|
0c31eaee61 | ||
|
|
e73c12cac2 |
25
flake.lock
generated
Normal file
25
flake.lock
generated
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1690630721,
|
||||
"narHash": "sha256-Y04onHyBQT4Erfr2fc82dbJTfXGYrf4V0ysLUYnPOP8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "d2b52322f35597c62abf56de91b0236746b2a03d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
81
flake.nix
Normal file
81
flake.nix
Normal file
@@ -0,0 +1,81 @@
|
||||
# Important note: this flake does not attempt to create a fully isolated, 'pure'
|
||||
# Python environment for InvokeAI. Instead, it depends on local invocations of
|
||||
# virtualenv/pip to install the required (binary) packages, most importantly the
|
||||
# prebuilt binary pytorch packages with CUDA support.
|
||||
# ML Python packages with CUDA support, like pytorch, are notoriously expensive
|
||||
# to compile so it's purposefuly not what this flake does.
|
||||
|
||||
{
|
||||
description = "An (impure) flake to develop on InvokeAI.";
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
|
||||
python = pkgs.python310;
|
||||
|
||||
mkShell = { dir, install }:
|
||||
let
|
||||
setupScript = pkgs.writeScript "setup-invokai" ''
|
||||
# This must be sourced using 'source', not executed.
|
||||
${python}/bin/python -m venv ${dir}
|
||||
${dir}/bin/python -m pip install ${install}
|
||||
# ${dir}/bin/python -c 'import torch; assert(torch.cuda.is_available())'
|
||||
source ${dir}/bin/activate
|
||||
'';
|
||||
in
|
||||
pkgs.mkShell rec {
|
||||
buildInputs = with pkgs; [
|
||||
# Backend: graphics, CUDA.
|
||||
cudaPackages.cudnn
|
||||
cudaPackages.cuda_nvrtc
|
||||
cudatoolkit
|
||||
freeglut
|
||||
glib
|
||||
gperf
|
||||
procps
|
||||
libGL
|
||||
libGLU
|
||||
linuxPackages.nvidia_x11
|
||||
python
|
||||
stdenv.cc
|
||||
stdenv.cc.cc.lib
|
||||
xorg.libX11
|
||||
xorg.libXext
|
||||
xorg.libXi
|
||||
xorg.libXmu
|
||||
xorg.libXrandr
|
||||
xorg.libXv
|
||||
zlib
|
||||
|
||||
# Pre-commit hooks.
|
||||
black
|
||||
|
||||
# Frontend.
|
||||
yarn
|
||||
nodejs
|
||||
];
|
||||
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
|
||||
CUDA_PATH = pkgs.cudatoolkit;
|
||||
EXTRA_LDFLAGS = "-L${pkgs.linuxPackages.nvidia_x11}/lib";
|
||||
shellHook = ''
|
||||
if [[ -f "${dir}/bin/activate" ]]; then
|
||||
source "${dir}/bin/activate"
|
||||
echo "Using Python: $(which python)"
|
||||
else
|
||||
echo "Use 'source ${setupScript}' to set up the environment."
|
||||
fi
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
devShells.${system} = rec {
|
||||
develop = mkShell { dir = "venv"; install = "-e '.[xformers]' --extra-index-url https://download.pytorch.org/whl/cu118"; };
|
||||
default = develop;
|
||||
};
|
||||
};
|
||||
}
|
||||
52
invokeai/app/invocations/translate.py
Normal file
52
invokeai/app/invocations/translate.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2023 Lincoln D. Stein
|
||||
|
||||
from typing import Literal, Union, List
|
||||
from pydantic import Field
|
||||
from .baseinvocation import (
|
||||
BaseInvocation,
|
||||
BaseInvocationOutput,
|
||||
InvocationContext,
|
||||
InvocationConfig,
|
||||
)
|
||||
|
||||
# from .params import StringOutput
|
||||
|
||||
translate_available = False
|
||||
try:
|
||||
import translators as ts
|
||||
|
||||
translate_available = True
|
||||
TRANSLATORS = tuple(ts.translators_pool)
|
||||
except:
|
||||
TRANSLATORS = ("google", "bing")
|
||||
|
||||
DEFAULT_PROMPT = "" if translate_available else "To use this node, please 'pip install --upgrade translators'"
|
||||
|
||||
|
||||
class TranslateOutput(BaseInvocationOutput):
|
||||
"""Translated string output"""
|
||||
|
||||
type: Literal["translated_string_output"] = "translated_string_output"
|
||||
prompt: str = Field(default=None, description="The translated prompt string")
|
||||
|
||||
|
||||
class TranslateInvocation(BaseInvocation):
|
||||
"""Use the translators package to translate 330 languages into English prompts"""
|
||||
|
||||
# fmt: off
|
||||
type: Literal["translate"] = "translate"
|
||||
|
||||
# Inputs
|
||||
text: str = Field(default=DEFAULT_PROMPT, description="Prompt in any language")
|
||||
translator: Literal[TRANSLATORS] = Field(default="google", description="The translator service to use")
|
||||
# fmt: on
|
||||
|
||||
# Schema customisation
|
||||
class Config(InvocationConfig):
|
||||
schema_extra = {
|
||||
"ui": {"title": "Translate", "tags": ["prompt", "translate", "translator"]},
|
||||
}
|
||||
|
||||
def invoke(self, context: InvocationContext) -> TranslateOutput:
|
||||
translation: str = ts.translate_text(self.text, translator=self.translator)
|
||||
return TranslateOutput(prompt=translation)
|
||||
@@ -174,6 +174,7 @@ INIT_FILE = Path("invokeai.yaml")
|
||||
DB_FILE = Path("invokeai.db")
|
||||
LEGACY_INIT_FILE = Path("invokeai.init")
|
||||
|
||||
|
||||
class InvokeAISettings(BaseSettings):
|
||||
"""
|
||||
Runtime configuration settings in which default values are
|
||||
@@ -273,7 +274,7 @@ class InvokeAISettings(BaseSettings):
|
||||
@classmethod
|
||||
def _excluded(self) -> List[str]:
|
||||
# internal fields that shouldn't be exposed as command line options
|
||||
return ["type", "initconf","cached_root"]
|
||||
return ["type", "initconf", "cached_root"]
|
||||
|
||||
@classmethod
|
||||
def _excluded_from_yaml(self) -> List[str]:
|
||||
@@ -362,6 +363,7 @@ def _find_root() -> Path:
|
||||
root = Path("~/invokeai").expanduser().resolve()
|
||||
return root
|
||||
|
||||
|
||||
class InvokeAIAppConfig(InvokeAISettings):
|
||||
"""
|
||||
Generate images using Stable Diffusion. Use "invokeai" to launch
|
||||
|
||||
@@ -320,7 +320,7 @@ class mergeModelsForm(npyscreen.FormMultiPageAction):
|
||||
|
||||
def get_model_names(self, base_model: BaseModelType = None) -> List[str]:
|
||||
model_names = [
|
||||
info["name"]
|
||||
info["model_name"]
|
||||
for info in self.model_manager.list_models(model_type=ModelType.Main, base_model=base_model)
|
||||
if info["model_format"] == "diffusers"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user