Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1965,13 +1965,19 @@ def similarity_matching(input_json_path: str, project_folder:str) -> str:
|
|
1965 |
with open(sprite_json_path, 'r') as f:
|
1966 |
sprite_data = json.load(f)
|
1967 |
# print(f"SPRITE DATA: \n{sprite_data}")
|
1968 |
-
# Copy only non-matched files
|
|
|
|
|
|
|
|
|
|
|
|
|
1969 |
for fname in os.listdir(matched_folder):
|
1970 |
fpath = os.path.join(matched_folder, fname)
|
|
|
1971 |
if os.path.isfile(fpath) and fname not in {os.path.basename(matched_image_path), 'sprite.json'}:
|
1972 |
-
shutil.copy2(fpath,
|
1973 |
-
|
1974 |
-
project_data.append(sprite_data)
|
1975 |
|
1976 |
# ================================================================== #
|
1977 |
# Loop through most similar images from Backdrops folder #
|
@@ -1991,11 +1997,18 @@ def similarity_matching(input_json_path: str, project_folder:str) -> str:
|
|
1991 |
logger.info(f"Backdrop matched image: {matched_image_path}")
|
1992 |
|
1993 |
# Copy only non-matched files
|
|
|
|
|
|
|
|
|
|
|
1994 |
for fname in os.listdir(matched_folder):
|
1995 |
fpath = os.path.join(matched_folder, fname)
|
|
|
1996 |
if os.path.isfile(fpath) and fname not in {os.path.basename(matched_image_path), 'project.json'}:
|
1997 |
-
shutil.copy2(fpath,
|
1998 |
-
|
|
|
1999 |
|
2000 |
# Append backdrop's project.json
|
2001 |
backdrop_json_path = os.path.join(matched_folder, 'project.json')
|
@@ -2117,11 +2130,13 @@ def create_sb3_archive(project_folder: Path, project_id: str) -> Path | None:
|
|
2117 |
Returns:
|
2118 |
Path: The path to the created .sb3 file, or None if an error occurred.
|
2119 |
"""
|
|
|
2120 |
output_base_name = GEN_PROJECT_DIR / project_id
|
2121 |
zip_path = None
|
2122 |
sb3_path = None
|
2123 |
try:
|
2124 |
# shutil.make_archive automatically adds .zip extension
|
|
|
2125 |
zip_path_str = shutil.make_archive(str(output_base_name), 'zip', root_dir=str(project_folder))
|
2126 |
zip_path = Path(zip_path_str) # Convert back to Path object
|
2127 |
logger.info(f"Project folder zipped to: {zip_path}")
|
@@ -2227,19 +2242,19 @@ def process_pdf():
|
|
2227 |
img_bytes = buf.getvalue()
|
2228 |
img_b64 = base64.b64encode(img_bytes).decode("utf-8")
|
2229 |
|
2230 |
-
initial_state_dict = {
|
2231 |
-
|
2232 |
-
|
2233 |
-
|
2234 |
-
|
2235 |
-
|
2236 |
-
|
2237 |
-
|
2238 |
-
}
|
2239 |
|
2240 |
-
final_state_dict = app_graph.invoke(initial_state_dict)
|
2241 |
|
2242 |
-
final_project_json = final_state_dict['project_json']
|
2243 |
|
2244 |
with open(project_output, "w") as f:
|
2245 |
json.dump(final_project_json, f, indent=2)
|
|
|
1965 |
with open(sprite_json_path, 'r') as f:
|
1966 |
sprite_data = json.load(f)
|
1967 |
# print(f"SPRITE DATA: \n{sprite_data}")
|
1968 |
+
# # Copy only non-matched files
|
1969 |
+
# for fname in os.listdir(matched_folder):
|
1970 |
+
# fpath = os.path.join(matched_folder, fname)
|
1971 |
+
# if os.path.isfile(fpath) and fname not in {os.path.basename(matched_image_path), 'sprite.json'}:
|
1972 |
+
# shutil.copy2(fpath, os.path.join(project_folder, fname))
|
1973 |
+
# # logger.info(f"Copied Sprite asset: {fname}")
|
1974 |
+
project_data.append(sprite_data)
|
1975 |
for fname in os.listdir(matched_folder):
|
1976 |
fpath = os.path.join(matched_folder, fname)
|
1977 |
+
dest_path = os.path.join(project_folder, fname)
|
1978 |
if os.path.isfile(fpath) and fname not in {os.path.basename(matched_image_path), 'sprite.json'}:
|
1979 |
+
shutil.copy2(fpath, dest_path)
|
1980 |
+
logger.info(f"🟢 Copied Sprite Asset: {fpath} → {dest_path}")
|
|
|
1981 |
|
1982 |
# ================================================================== #
|
1983 |
# Loop through most similar images from Backdrops folder #
|
|
|
1997 |
logger.info(f"Backdrop matched image: {matched_image_path}")
|
1998 |
|
1999 |
# Copy only non-matched files
|
2000 |
+
# for fname in os.listdir(matched_folder):
|
2001 |
+
# fpath = os.path.join(matched_folder, fname)
|
2002 |
+
# if os.path.isfile(fpath) and fname not in {os.path.basename(matched_image_path), 'project.json'}:
|
2003 |
+
# shutil.copy2(fpath, os.path.join(project_folder, fname))
|
2004 |
+
# # logger.info(f"Copied Backdrop asset: {fname}")
|
2005 |
for fname in os.listdir(matched_folder):
|
2006 |
fpath = os.path.join(matched_folder, fname)
|
2007 |
+
dest_path = os.path.join(project_folder, fname)
|
2008 |
if os.path.isfile(fpath) and fname not in {os.path.basename(matched_image_path), 'project.json'}:
|
2009 |
+
shutil.copy2(fpath, dest_path)
|
2010 |
+
logger.info(f"🟡 Copied Backdrop Asset: {fpath} → {dest_path}")
|
2011 |
+
|
2012 |
|
2013 |
# Append backdrop's project.json
|
2014 |
backdrop_json_path = os.path.join(matched_folder, 'project.json')
|
|
|
2130 |
Returns:
|
2131 |
Path: The path to the created .sb3 file, or None if an error occurred.
|
2132 |
"""
|
2133 |
+
print(" --------------------------------------- create_sb3_archive INITIALIZE ---------------------------------------")
|
2134 |
output_base_name = GEN_PROJECT_DIR / project_id
|
2135 |
zip_path = None
|
2136 |
sb3_path = None
|
2137 |
try:
|
2138 |
# shutil.make_archive automatically adds .zip extension
|
2139 |
+
print(" --------------------------------------- zip_path_str ---------------------------------------", output_base_name, project_folder)
|
2140 |
zip_path_str = shutil.make_archive(str(output_base_name), 'zip', root_dir=str(project_folder))
|
2141 |
zip_path = Path(zip_path_str) # Convert back to Path object
|
2142 |
logger.info(f"Project folder zipped to: {zip_path}")
|
|
|
2242 |
img_bytes = buf.getvalue()
|
2243 |
img_b64 = base64.b64encode(img_bytes).decode("utf-8")
|
2244 |
|
2245 |
+
# initial_state_dict = {
|
2246 |
+
# "project_json": project_skeleton,
|
2247 |
+
# "description": "The pseudo code for the script",
|
2248 |
+
# "project_id": project_id,
|
2249 |
+
# "project_image": img_b64,
|
2250 |
+
# "action_plan": {},
|
2251 |
+
# "pseudo_code": {},
|
2252 |
+
# "temporary_node": {},
|
2253 |
+
# }
|
2254 |
|
2255 |
+
# final_state_dict = app_graph.invoke(initial_state_dict)
|
2256 |
|
2257 |
+
final_project_json = project_skeleton # final_state_dict['project_json']
|
2258 |
|
2259 |
with open(project_output, "w") as f:
|
2260 |
json.dump(final_project_json, f, indent=2)
|