Update app.py
Browse files
app.py
CHANGED
|
@@ -1847,17 +1847,17 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
|
|
| 1847 |
print("matched_filename ---3-->",matched_filename)
|
| 1848 |
|
| 1849 |
|
| 1850 |
-
# resolve matched_folder (safe even if it's already absolute)
|
| 1851 |
-
try:
|
| 1852 |
-
|
| 1853 |
-
except Exception:
|
| 1854 |
-
|
| 1855 |
-
|
| 1856 |
|
| 1857 |
-
print(f"Processing matched image: {matched_image_path}")
|
| 1858 |
-
print(f" matched_folder_p = {matched_folder_p}")
|
| 1859 |
-
print(f" sprite_base_p = {sprite_base_p}")
|
| 1860 |
-
print(f" backdrop_base_p = {backdrop_base_p}")
|
| 1861 |
|
| 1862 |
# Check if matched_folder is under sprite_base_p
|
| 1863 |
is_sprite = False
|
|
@@ -1870,12 +1870,12 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
|
|
| 1870 |
is_sprite = False
|
| 1871 |
print("is_sprite---------->",is_sprite)
|
| 1872 |
|
| 1873 |
-
if is_sprite and str(
|
| 1874 |
-
print(f"Processing SPRITE folder: {
|
| 1875 |
-
copied_sprite_folders.add(str(
|
| 1876 |
-
sprite_json_path =
|
| 1877 |
# ... (rest of your logic, but use Path objects)
|
| 1878 |
-
sprite_files = list(
|
| 1879 |
print(f" Files in sprite folder: {[p.name for p in sprite_files]}")
|
| 1880 |
for p in sprite_files:
|
| 1881 |
fname = p.name
|
|
@@ -1895,7 +1895,7 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
|
|
| 1895 |
# Check if matched_folder is under backdrop_base_p
|
| 1896 |
is_backdrop = False
|
| 1897 |
try:
|
| 1898 |
-
|
| 1899 |
print("matched_folder_p--------->",matched_folder_p)
|
| 1900 |
is_backdrop = True
|
| 1901 |
print("is_backdrop---------->",is_backdrop)
|
|
@@ -1903,20 +1903,20 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
|
|
| 1903 |
is_backdrop = False
|
| 1904 |
print("is_backdrop---------->",is_backdrop)
|
| 1905 |
|
| 1906 |
-
if is_backdrop and str(
|
| 1907 |
-
print(f"Processing BACKDROP folder: {
|
| 1908 |
-
copied_backdrop_folders.add(str(
|
| 1909 |
# copy matched backdrop image
|
| 1910 |
backdrop_dst = project_folder_p / matched_filename
|
| 1911 |
try:
|
| 1912 |
-
shutil.copy2(str(
|
| 1913 |
-
print(f" ✓ Copied matched backdrop image: {
|
| 1914 |
except Exception as e:
|
| 1915 |
-
print(f" ✗ Failed to copy matched backdrop image {
|
| 1916 |
|
| 1917 |
# copy other files similarly using Path.iterdir()
|
| 1918 |
-
# read project.json at
|
| 1919 |
-
pj =
|
| 1920 |
if pj.exists():
|
| 1921 |
try:
|
| 1922 |
with pj.open("r", encoding="utf-8") as f:
|
|
@@ -1926,11 +1926,11 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
|
|
| 1926 |
if tgt.get("isStage"):
|
| 1927 |
backdrop_data.append(tgt)
|
| 1928 |
stage_count += 1
|
| 1929 |
-
print(f" ✓ Successfully read project.json from {
|
| 1930 |
except Exception as e:
|
| 1931 |
-
print(f" ✗ Failed to read project.json in {
|
| 1932 |
else:
|
| 1933 |
-
print(f" ⚠ No project.json in {
|
| 1934 |
|
| 1935 |
print("---")
|
| 1936 |
|
|
|
|
| 1847 |
print("matched_filename ---3-->",matched_filename)
|
| 1848 |
|
| 1849 |
|
| 1850 |
+
# # resolve matched_folder (safe even if it's already absolute)
|
| 1851 |
+
# try:
|
| 1852 |
+
# matched_folder_p = matched_folder.resolve()
|
| 1853 |
+
# except Exception:
|
| 1854 |
+
# # fallback to absolute path join if resolve fails
|
| 1855 |
+
# matched_folder_p = (Path.cwd() / matched_folder).resolve()
|
| 1856 |
|
| 1857 |
+
# print(f"Processing matched image: {matched_image_path}")
|
| 1858 |
+
# print(f" matched_folder_p = {matched_folder_p}")
|
| 1859 |
+
# print(f" sprite_base_p = {sprite_base_p}")
|
| 1860 |
+
# print(f" backdrop_base_p = {backdrop_base_p}")
|
| 1861 |
|
| 1862 |
# Check if matched_folder is under sprite_base_p
|
| 1863 |
is_sprite = False
|
|
|
|
| 1870 |
is_sprite = False
|
| 1871 |
print("is_sprite---------->",is_sprite)
|
| 1872 |
|
| 1873 |
+
if is_sprite and str(matched_folder) not in copied_sprite_folders:
|
| 1874 |
+
print(f"Processing SPRITE folder: {matched_folder}")
|
| 1875 |
+
copied_sprite_folders.add(str(matched_folder))
|
| 1876 |
+
sprite_json_path = matched_folder / "sprite.json"
|
| 1877 |
# ... (rest of your logic, but use Path objects)
|
| 1878 |
+
sprite_files = list(matched_folder.iterdir())
|
| 1879 |
print(f" Files in sprite folder: {[p.name for p in sprite_files]}")
|
| 1880 |
for p in sprite_files:
|
| 1881 |
fname = p.name
|
|
|
|
| 1895 |
# Check if matched_folder is under backdrop_base_p
|
| 1896 |
is_backdrop = False
|
| 1897 |
try:
|
| 1898 |
+
matched_folder.relative_to(backdrop_base_p)
|
| 1899 |
print("matched_folder_p--------->",matched_folder_p)
|
| 1900 |
is_backdrop = True
|
| 1901 |
print("is_backdrop---------->",is_backdrop)
|
|
|
|
| 1903 |
is_backdrop = False
|
| 1904 |
print("is_backdrop---------->",is_backdrop)
|
| 1905 |
|
| 1906 |
+
if is_backdrop and str(matched_folder) not in copied_backdrop_folders:
|
| 1907 |
+
print(f"Processing BACKDROP folder: {matched_folder}")
|
| 1908 |
+
copied_backdrop_folders.add(str(matched_folder))
|
| 1909 |
# copy matched backdrop image
|
| 1910 |
backdrop_dst = project_folder_p / matched_filename
|
| 1911 |
try:
|
| 1912 |
+
shutil.copy2(str(matched_folder / matched_filename), str(backdrop_dst))
|
| 1913 |
+
print(f" ✓ Copied matched backdrop image: {matched_folder / matched_filename} -> {backdrop_dst}")
|
| 1914 |
except Exception as e:
|
| 1915 |
+
print(f" ✗ Failed to copy matched backdrop image {matched_folder / matched_filename}: {e}")
|
| 1916 |
|
| 1917 |
# copy other files similarly using Path.iterdir()
|
| 1918 |
+
# read project.json at matched_folder / "project.json"
|
| 1919 |
+
pj = matched_folder / "project.json"
|
| 1920 |
if pj.exists():
|
| 1921 |
try:
|
| 1922 |
with pj.open("r", encoding="utf-8") as f:
|
|
|
|
| 1926 |
if tgt.get("isStage"):
|
| 1927 |
backdrop_data.append(tgt)
|
| 1928 |
stage_count += 1
|
| 1929 |
+
print(f" ✓ Successfully read project.json from {matched_folder}, found {stage_count} stage(s)")
|
| 1930 |
except Exception as e:
|
| 1931 |
+
print(f" ✗ Failed to read project.json in {matched_folder}: {e}")
|
| 1932 |
else:
|
| 1933 |
+
print(f" ⚠ No project.json in {matched_folder}")
|
| 1934 |
|
| 1935 |
print("---")
|
| 1936 |
|