Skip to content

Image Pipeline Playground

fix(server): update default port from 8765 to 8000 in run_server.py and main.py

Mohammad Rajaeic2970f2042c9
diff --git a/backend/app/main.py b/backend/app/main.py
index fb53249..afe53e2 100644
--- a/backend/app/main.py
+++ b/backend/app/main.py
@@ -20,8 +20,8 @@ app.add_middleware(
allow_origins=[
"http://localhost:5173",
"http://127.0.0.1:5173",
- "http://localhost:8765",
- "http://127.0.0.1:8765",
+ "http://localhost:8000",
+ "http://127.0.0.1:8000",
"http://localhost:8000",
"http://127.0.0.1:8000",
"null",
diff --git a/backend/app/nodes/io.py b/backend/app/nodes/io.py
index 7b97541..d258042 100644
--- a/backend/app/nodes/io.py
+++ b/backend/app/nodes/io.py
@@ -26,6 +26,7 @@ from app.nodes.common import (
select_param,
string_param,
)
+from app.paths import resolve_load_path
def _normalized_extensions(extensions: list[str] | None = None) -> set[str]:
@@ -80,7 +81,7 @@ class LoadImageNode(BaseNode):
current_source_stems.set([])
return
try:
- files = list_image_files(Path(path_value))
+ files = list_image_files(resolve_load_path(path_value))
current_source_stems.set([file_path.stem for file_path in files])
except (OSError, ValueError, FileNotFoundError):
current_source_stems.set([])
@@ -94,7 +95,7 @@ class LoadImageNode(BaseNode):
path_value = str(params["path"])
if not path_value:
raise ValueError("Load Images requires a file or folder selection")
- path = Path(path_value)
+ path = resolve_load_path(path_value)
files = list_image_files(path)
current_source_stems.set([file_path.stem for file_path in files])
images = [read_image(file_path) for file_path in files]
@@ -107,7 +108,7 @@ class LoadImageNode(BaseNode):
input_vars: dict[str, str],
output_vars: dict[str, str],
) -> list[str]:
- path = params["path"]
+ path = str(resolve_load_path(str(params["path"])))
dst = output_vars["image"]
return [
f"_path = Path({path!r})",
diff --git a/backend/app/paths.py b/backend/app/paths.py
index 64955c7..3c633f3 100644
--- a/backend/app/paths.py
+++ b/backend/app/paths.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import os
+import sys
from pathlib import Path
@@ -17,6 +18,50 @@ def data_root() -> Path:
return root
+def examples_dir() -> Path:
+ """Directory containing bundled example assets (e.g. lena.png)."""
+ override = os.environ.get("IMAGE_PIPES_EXAMPLES_DIR")
+ if override:
+ return Path(override)
+ # Source / normal install: backend/examples (this file is backend/app/paths.py)
+ candidate = Path(__file__).resolve().parents[1] / "examples"
+ if candidate.exists():
+ return candidate
+ if getattr(sys, "frozen", False):
+ beside = Path(sys.executable).resolve().parent / "examples"
+ if beside.exists():
+ return beside
+ meipass = getattr(sys, "_MEIPASS", None)
+ if meipass:
+ bundled = Path(meipass) / "examples"
+ if bundled.exists():
+ return bundled
+ return candidate
+
+
+def resolve_load_path(path_value: str) -> Path:
+ """Resolve a load_image path, including portable example-relative paths.
+
+ Template workflows store paths like ``examples/lena.png``. Those only exist
+ when the process cwd is the backend root; resolve against ``examples_dir()``
+ so loads work regardless of how the server was started.
+ """
+ path = Path(path_value)
+ if path.exists():
+ return path
+ if path.is_absolute():
+ return path
+ # ``examples/lena.png`` → ``<backend>/examples/lena.png``
+ relative_to_backend = examples_dir().parent / path
+ if relative_to_backend.exists():
+ return relative_to_backend
+ # Bare filename → look under examples/
+ under_examples = examples_dir() / path
+ if under_examples.exists():
+ return under_examples
+ return path
+
+
def cache_dir() -> Path:
path = data_root() / "cache"
path.mkdir(parents=True, exist_ok=True)
diff --git a/backend/run_server.py b/backend/run_server.py
index 8e47dbd..7cccb0b 100644
--- a/backend/run_server.py
+++ b/backend/run_server.py
@@ -37,7 +37,7 @@ def main() -> None:
_prepare_environment()
host = os.environ.get("IMAGE_PIPES_HOST", "127.0.0.1")
- port = int(os.environ.get("IMAGE_PIPES_PORT", "8765"))
+ port = int(os.environ.get("IMAGE_PIPES_PORT", "8000"))
import uvicorn
diff --git a/backend/tests/test_load_image.py b/backend/tests/test_load_image.py
index 89a86c1..c64c9e1 100644
--- a/backend/tests/test_load_image.py
+++ b/backend/tests/test_load_image.py
@@ -10,6 +10,7 @@ import numpy as np
from app.engine.registry import registry
from app.nodes import register_builtin_nodes
from app.nodes.io import list_image_files
+from app.paths import examples_dir, resolve_load_path
def _write(path: Path, value: int) -> None:
@@ -45,6 +46,25 @@ def test_load_image_single_file_still_returns_list(tmp_path: Path) -> None:
assert len(loaded) == 1
+def test_resolve_load_path_finds_bundled_example(tmp_path: Path, monkeypatch) -> None:
+ lena = examples_dir() / "lena.png"
+ assert lena.is_file(), f"expected bundled example at {lena}"
+ monkeypatch.chdir(tmp_path)
+ resolved = resolve_load_path("examples/lena.png")
+ assert resolved.resolve() == lena.resolve()
+
+
+def test_load_image_accepts_relative_example_path(tmp_path: Path, monkeypatch) -> None:
+ register_builtin_nodes()
+ monkeypatch.chdir(tmp_path)
+ loaded = registry.get("load_image").execute(
+ {}, {"path": "examples/lena.png"}, seed=0
+ )["image"]
+ assert isinstance(loaded, list)
+ assert len(loaded) == 1
+ assert loaded[0].ndim >= 2
+
+
def test_load_image_metadata_exposes_file_accept() -> None:
register_builtin_nodes()
meta = next(item for item in registry.list_metadata() if item.type == "load_image")