Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1957,18 +1957,39 @@ def similarity_matching(input_json_path: str, project_folder: str) -> str:
|
|
1957 |
for backdrop_idx, matched_idx in enumerate(most_similar_indices):
|
1958 |
matched_image_path = folder_image_paths[matched_idx]
|
1959 |
matched_folder = os.path.dirname(matched_image_path)
|
1960 |
-
|
|
|
1961 |
# CHANGED: use our new normalized backdrop_base_path
|
1962 |
if not matched_folder.startswith(backdrop_base_path):
|
1963 |
continue
|
1964 |
|
1965 |
logger.info(f"Matched backdrop: {matched_image_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1966 |
# copy non‐matched files
|
1967 |
for fname in os.listdir(matched_folder):
|
1968 |
-
if fname in (os.path.basename(matched_image_path), 'project.json'):
|
|
|
1969 |
continue
|
1970 |
-
shutil.copy2(os.path.join(matched_folder, fname),
|
1971 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1972 |
|
1973 |
# append the stage‐target from its project.json
|
1974 |
pj = os.path.join(matched_folder, 'project.json')
|
|
|
1957 |
for backdrop_idx, matched_idx in enumerate(most_similar_indices):
|
1958 |
matched_image_path = folder_image_paths[matched_idx]
|
1959 |
matched_folder = os.path.dirname(matched_image_path)
|
1960 |
+
matched_filename = os.path.basename(matched_image_path)
|
1961 |
+
|
1962 |
# CHANGED: use our new normalized backdrop_base_path
|
1963 |
if not matched_folder.startswith(backdrop_base_path):
|
1964 |
continue
|
1965 |
|
1966 |
logger.info(f"Matched backdrop: {matched_image_path}")
|
1967 |
+
|
1968 |
+
# 1) Copy the matched backdrop image itself
|
1969 |
+
try:
|
1970 |
+
shutil.copy2(
|
1971 |
+
matched_image_path,
|
1972 |
+
os.path.join(project_folder, matched_filename)
|
1973 |
+
)
|
1974 |
+
logger.info(f"✅ Copied matched backdrop image {matched_filename} to {project_folder}")
|
1975 |
+
except Exception as e:
|
1976 |
+
logger.error(f"❌ Failed to copy matched backdrop {matched_image_path}: {e}")
|
1977 |
+
|
1978 |
# copy non‐matched files
|
1979 |
for fname in os.listdir(matched_folder):
|
1980 |
+
# if fname in (os.path.basename(matched_image_path), 'project.json'):
|
1981 |
+
if fname in {matched_filename, 'project.json'}:
|
1982 |
continue
|
1983 |
+
# shutil.copy2(os.path.join(matched_folder, fname),
|
1984 |
+
# os.path.join(project_folder, fname))
|
1985 |
+
src = os.path.join(matched_folder, fname)
|
1986 |
+
dst = os.path.join(project_folder, fname)
|
1987 |
+
if os.path.isfile(src):
|
1988 |
+
try:
|
1989 |
+
shutil.copy2(src, dst)
|
1990 |
+
logger.info(f"Copied additional backdrop asset {fname} to project folder")
|
1991 |
+
except Exception as e:
|
1992 |
+
logger.error(f"Failed to copy {src}: {e}")
|
1993 |
|
1994 |
# append the stage‐target from its project.json
|
1995 |
pj = os.path.join(matched_folder, 'project.json')
|