prthm11 commited on
Commit
2d16363
·
verified ·
1 Parent(s): 640bc5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -22,6 +22,17 @@ from io import BytesIO
22
  from pathlib import Path
23
  import os
24
  from utils.block_relation_builder_v1 import block_builder, variable_adder_main
 
 
 
 
 
 
 
 
 
 
 
25
  global pdf_doc
26
  # ============================== #
27
  # INITIALIZE CLIP EMBEDDER #
@@ -1917,6 +1928,7 @@ def plan_logic_aligner_node(state: GameState):
1917
  # Prepare manipulated sprite JSON structure
1918
  manipulated_json = {}
1919
  img_elements = []
 
1920
  # { changes: "pdf_stream" in place of "pdf_path"
1921
  def extract_images_from_pdf(pdf_stream: io.BytesIO):
1922
  ''' Extract images from PDF and generate structured sprite JSON '''
@@ -1999,6 +2011,7 @@ def extract_images_from_pdf(pdf_stream: io.BytesIO):
1999
  except Exception as e:
2000
  raise RuntimeError(f"❌ Error in extract_images_from_pdf: {str(e)}")
2001
 
 
2002
  # def similarity_matching(input_json_path: str, project_folder: str) -> str:
2003
  def similarity_matching(sprites_data: str, project_folder: str) -> str:
2004
  logger.info("🔍 Running similarity matching…")
@@ -2374,6 +2387,7 @@ def similarity_matching(sprites_data: str, project_folder: str) -> str:
2374
  # buf.seek(0)
2375
  # buffers.append(buf)
2376
  # return buffers
 
2377
  def convert_pdf_stream_to_images(pdf_stream: io.BytesIO, dpi=300):
2378
  # Ensure we are at the start of the stream
2379
  pdf_stream.seek(0)
@@ -2436,7 +2450,8 @@ def upscale_image(image: Image.Image, scale: int = 2) -> Image.Image:
2436
  except Exception as e:
2437
  logger.error(f"❌ Error during image upscaling: {str(e)}")
2438
  return image
2439
-
 
2440
  def create_sb3_archive(project_folder, project_id):
2441
  """
2442
  Zips the project folder and renames it to an .sb3 file.
@@ -2476,6 +2491,7 @@ def create_sb3_archive(project_folder, project_id):
2476
  os.remove(sb3_path)
2477
  return sb3_path
2478
 
 
2479
  #{ changes -> pdf_stream replacement of pdf_path
2480
  # def save_pdf_to_generated_dir(pdf_path: str, project_id: str) -> str:
2481
  def save_pdf_to_generated_dir(pdf_stream: io.BytesIO, project_id: str) -> str:
 
22
  from pathlib import Path
23
  import os
24
  from utils.block_relation_builder_v1 import block_builder, variable_adder_main
25
+
26
+ def log_execution_time(func):
27
+ @functools.wraps(func)
28
+ def wrapper(*args, **kwargs):
29
+ start_time = time.time()
30
+ result = func(*args, **kwargs)
31
+ end_time = time.time()
32
+ logger.info(f"⏱ {func.__name__} executed in {end_time - start_time:.2f} seconds")
33
+ return result
34
+ return wrapper
35
+
36
  global pdf_doc
37
  # ============================== #
38
  # INITIALIZE CLIP EMBEDDER #
 
1928
  # Prepare manipulated sprite JSON structure
1929
  manipulated_json = {}
1930
  img_elements = []
1931
+ @log_execution_time
1932
  # { changes: "pdf_stream" in place of "pdf_path"
1933
  def extract_images_from_pdf(pdf_stream: io.BytesIO):
1934
  ''' Extract images from PDF and generate structured sprite JSON '''
 
2011
  except Exception as e:
2012
  raise RuntimeError(f"❌ Error in extract_images_from_pdf: {str(e)}")
2013
 
2014
+ @log_execution_time
2015
  # def similarity_matching(input_json_path: str, project_folder: str) -> str:
2016
  def similarity_matching(sprites_data: str, project_folder: str) -> str:
2017
  logger.info("🔍 Running similarity matching…")
 
2387
  # buf.seek(0)
2388
  # buffers.append(buf)
2389
  # return buffers
2390
+ @log_execution_time
2391
  def convert_pdf_stream_to_images(pdf_stream: io.BytesIO, dpi=300):
2392
  # Ensure we are at the start of the stream
2393
  pdf_stream.seek(0)
 
2450
  except Exception as e:
2451
  logger.error(f"❌ Error during image upscaling: {str(e)}")
2452
  return image
2453
+
2454
+ @log_execution_time
2455
  def create_sb3_archive(project_folder, project_id):
2456
  """
2457
  Zips the project folder and renames it to an .sb3 file.
 
2491
  os.remove(sb3_path)
2492
  return sb3_path
2493
 
2494
+ @log_execution_time
2495
  #{ changes -> pdf_stream replacement of pdf_path
2496
  # def save_pdf_to_generated_dir(pdf_path: str, project_id: str) -> str:
2497
  def save_pdf_to_generated_dir(pdf_stream: io.BytesIO, project_id: str) -> str: