auto-git:

[change] main.py
This commit is contained in:
2026-05-14 10:37:54 +02:00
parent aaca619640
commit 483c0fe9a2

41
main.py
View File

@@ -11,6 +11,7 @@ import webview
import random import random
import subprocess import subprocess
import concurrent.futures import concurrent.futures
import shutil
from PIL import Image, PngImagePlugin from PIL import Image, PngImagePlugin
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import torch import torch
@@ -24,13 +25,9 @@ MODEL = "mistral:latest" # or "mistral-small3.1:24b"
# Path to your diffusers-converted model # Path to your diffusers-converted model
MODEL_PATH = "/Volumes/SD/ML-Models/diffusers/dreamshaper_8_diffusers" MODEL_PATH = "/Volumes/SD/ML-Models/diffusers/dreamshaper_8_diffusers"
# Where to save generated images IS_FROZEN = getattr(sys, "frozen", False)
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(sys.executable) if IS_FROZEN else os.path.dirname(os.path.abspath(__file__))
# ──────────────────────────────────────────────────────────────────────────── BUNDLE_DIR = getattr(sys, "_MEIPASS", BASE_DIR)
# Store everything under web/output instead of project_root/output
WEB_DIR = os.path.join(BASE_DIR, "web")
OUTPUT_DIR = os.path.join(WEB_DIR, "output")
os.makedirs(OUTPUT_DIR, exist_ok=True)
APP_SUPPORT_DIR = os.path.join( APP_SUPPORT_DIR = os.path.join(
os.path.expanduser("~"), os.path.expanduser("~"),
"Library", "Library",
@@ -40,6 +37,36 @@ APP_SUPPORT_DIR = os.path.join(
SETTINGS_PATH = os.path.join(APP_SUPPORT_DIR, "settings.json") SETTINGS_PATH = os.path.join(APP_SUPPORT_DIR, "settings.json")
# ──────────────────────────────────────────────────────────────────────────── # ────────────────────────────────────────────────────────────────────────────
def resource_path(*parts: str) -> str:
return os.path.join(BUNDLE_DIR, *parts)
def prepare_web_dir() -> str:
if not IS_FROZEN:
return os.path.join(BASE_DIR, "web")
src = resource_path("web")
dst = os.path.join(APP_SUPPORT_DIR, "web")
os.makedirs(dst, exist_ok=True)
for root, dirs, files in os.walk(src):
dirs[:] = [d for d in dirs if d != "output"]
rel = os.path.relpath(root, src)
out_root = dst if rel == "." else os.path.join(dst, rel)
os.makedirs(out_root, exist_ok=True)
for fname in files:
shutil.copy2(os.path.join(root, fname), os.path.join(out_root, fname))
return dst
WEB_DIR = prepare_web_dir()
WEB_INDEX = os.path.join(WEB_DIR, "index.html")
OUTPUT_DIR = os.path.join(WEB_DIR, "output")
APP_ICON_PATH = resource_path("icon.png")
os.makedirs(OUTPUT_DIR, exist_ok=True)
IMAGE_BACKEND_LOCAL = "local" IMAGE_BACKEND_LOCAL = "local"
IMAGE_BACKEND_REPLICATE = "replicate" IMAGE_BACKEND_REPLICATE = "replicate"
DEFAULT_IMAGE_BACKEND = IMAGE_BACKEND_LOCAL DEFAULT_IMAGE_BACKEND = IMAGE_BACKEND_LOCAL