Skip to content

Commit

Permalink
Merge pull request #76 from rupeshs/img-to-img-support
Browse files Browse the repository at this point in the history
Img to img support
  • Loading branch information
rupeshs authored Nov 26, 2023
2 parents f388720 + 4a3d145 commit 7b2d1c4
Show file tree
Hide file tree
Showing 24 changed files with 881 additions and 1,392 deletions.
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Using OpenVINO, it took 7 seconds to create a single 512x512 image on a Core i7-
- Lcm-Lora fused models for faster inference
- Supports integrated GPU(iGPU) using OpenVINO (export DEVICE=GPU)
- 5.7x speed using OpenVINO(steps: 2,tiny autoencoder)

- Image to Image support (Use Web UI)
- OpenVINO image to image support

## 2 Steps fast inference
FastSD CPU supports 2 to 3 steps fast inference using LCM-LoRA workflow. It works well with SD 1.5 models.
Expand Down
9 changes: 6 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from constants import APP_VERSION, LCM_DEFAULT_MODEL_OPENVINO
from models.interface_types import InterfaceType
from constants import DEVICE
from state import get_settings

parser = ArgumentParser(description=f"FAST SD CPU {constants.APP_VERSION}")
parser.add_argument(
Expand Down Expand Up @@ -141,8 +142,11 @@
# parser.print_help()
show_system_info()
print(f"Using device : {constants.DEVICE}")
app_settings = AppSettings()
app_settings.load()
if args.webui:
app_settings = get_settings()
else:
app_settings = get_settings()

print(f"Found {len(app_settings.lcm_models)} LCM models in config/lcm-models.txt")
print(
f"Found {len(app_settings.stable_diffsuion_models)} stable diffusion models in config/stable-diffusion-models.txt"
Expand All @@ -166,7 +170,6 @@

print("Starting web UI mode")
start_webui(
app_settings,
args.share,
)
elif args.realtime:
Expand Down
48 changes: 28 additions & 20 deletions src/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
SD_MODELS_FILE,
LCM_MODELS_FILE,
)
from copy import deepcopy


class AppSettings:
Expand Down Expand Up @@ -47,32 +48,39 @@ def lcm_models(self):
def lcm_lora_models(self):
return self._lcm_lora_models

def load(self):
if not path.exists(self.config_path):
base_dir = path.dirname(self.config_path)
if not path.exists(base_dir):
makedirs(base_dir)
def load(self, skip_file=False):
if skip_file:
print("Skipping config file")
settings_dict = self._load_default()
self._config = Settings.parse_obj(settings_dict)
else:
if not path.exists(self.config_path):
base_dir = path.dirname(self.config_path)
if not path.exists(base_dir):
makedirs(base_dir)
try:
print("Settings not found creating default settings")
with open(self.config_path, "w") as file:
yaml.dump(
self._load_default(),
file,
)
except Exception as ex:
print(f"Error in creating settings : {ex}")
exit()
try:
print("Settings not found creating default settings")
with open(self.config_path, "w") as file:
yaml.dump(
self._load_default(),
file,
)
with open(self.config_path) as file:
settings_dict = yaml.safe_load(file)
self._config = Settings.parse_obj(settings_dict)
except Exception as ex:
print(f"Error in creating settings : {ex}")
exit()
try:
with open(self.config_path) as file:
settings_dict = yaml.safe_load(file)
self._config = Settings.parse_obj(settings_dict)
except Exception as ex:
print(f"Error in loading settings : {ex}")
print(f"Error in loading settings : {ex}")

def save(self):
try:
with open(self.config_path, "w") as file:
yaml.dump(self._config.dict(), file)
tmp_cfg = deepcopy(self._config)
tmp_cfg.lcm_diffusion_setting.init_image = None
yaml.dump(tmp_cfg.dict(), file)
except Exception as ex:
print(f"Error in saving settings : {ex}")

Expand Down
3 changes: 2 additions & 1 deletion src/backend/image_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def save_images(
lcm_diffusion_setting: LCMDiffusionSetting = None,
) -> None:
gen_id = uuid4()

for index, image in enumerate(images):
if not path.exists(output_path):
mkdir(output_path)
Expand All @@ -33,7 +34,7 @@ def save_images(
if lcm_diffusion_setting:
with open(path.join(out_path, f"{gen_id}.json"), "w") as json_file:
json.dump(
lcm_diffusion_setting.model_dump(),
lcm_diffusion_setting.model_dump(exclude="init_image"),
json_file,
indent=4,
)
Loading

0 comments on commit 7b2d1c4

Please sign in to comment.