Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1652,19 +1652,21 @@ scratch_keywords = [
|
|
1652 |
]
|
1653 |
|
1654 |
#def extract_images_from_pdf(pdf_path: Path, json_base_dir: Path, image_base_dir: Path):
|
1655 |
-
def extract_images_from_pdf(pdf_path: Path, json_base_dir: Path):
|
|
|
1656 |
''' Extract images from PDF and generate structured sprite JSON '''
|
1657 |
try:
|
1658 |
pdf_path = Path(pdf_path)
|
1659 |
pdf_filename = pdf_path.stem # e.g., "scratch_crab"
|
1660 |
pdf_dir_path = str(pdf_path.parent).replace("/", "\\")
|
1661 |
print("-------------------------------pdf_filename-------------------------------",pdf_filename)
|
|
|
1662 |
# Create subfolders under the provided base directories
|
1663 |
# This will create paths like:
|
1664 |
# /app/detected_images/pdf_filename/
|
1665 |
# /app/json_data/pdf_filename/
|
1666 |
extracted_image_subdir = DETECTED_IMAGE_DIR / pdf_filename
|
1667 |
-
json_subdir =
|
1668 |
extracted_image_subdir.mkdir(parents=True, exist_ok=True)
|
1669 |
json_subdir.mkdir(parents=True, exist_ok=True)
|
1670 |
print("-------------------------------extracted_image_subdir-------------------------------",extracted_image_subdir)
|
@@ -2232,8 +2234,8 @@ def process_pdf():
|
|
2232 |
logger.info(f"Saved uploaded PDF to: {saved_pdf_path}")
|
2233 |
|
2234 |
# Extract & process
|
2235 |
-
|
2236 |
-
output_path, result = extract_images_from_pdf(saved_pdf_path
|
2237 |
print(" --------------------------------------- zip_path_str ---------------------------------------", output_path, result)
|
2238 |
# Check extracted_sprites.json for "scratch block" in any 'name'
|
2239 |
# extracted_dir = os.path.join(JSON_DIR, os.path.splitext(filename)[0])
|
|
|
1652 |
]
|
1653 |
|
1654 |
#def extract_images_from_pdf(pdf_path: Path, json_base_dir: Path, image_base_dir: Path):
|
1655 |
+
#def extract_images_from_pdf(pdf_path: Path, json_base_dir: Path):
|
1656 |
+
def extract_images_from_pdf(pdf_path: Path):
|
1657 |
''' Extract images from PDF and generate structured sprite JSON '''
|
1658 |
try:
|
1659 |
pdf_path = Path(pdf_path)
|
1660 |
pdf_filename = pdf_path.stem # e.g., "scratch_crab"
|
1661 |
pdf_dir_path = str(pdf_path.parent).replace("/", "\\")
|
1662 |
print("-------------------------------pdf_filename-------------------------------",pdf_filename)
|
1663 |
+
print("-------------------------------pdf_dir_path-------------------------------",pdf_dir_path)
|
1664 |
# Create subfolders under the provided base directories
|
1665 |
# This will create paths like:
|
1666 |
# /app/detected_images/pdf_filename/
|
1667 |
# /app/json_data/pdf_filename/
|
1668 |
extracted_image_subdir = DETECTED_IMAGE_DIR / pdf_filename
|
1669 |
+
json_subdir = JSON_DIR / pdf_filename
|
1670 |
extracted_image_subdir.mkdir(parents=True, exist_ok=True)
|
1671 |
json_subdir.mkdir(parents=True, exist_ok=True)
|
1672 |
print("-------------------------------extracted_image_subdir-------------------------------",extracted_image_subdir)
|
|
|
2234 |
logger.info(f"Saved uploaded PDF to: {saved_pdf_path}")
|
2235 |
|
2236 |
# Extract & process
|
2237 |
+
# output_path, result = extract_images_from_pdf(saved_pdf_path, json_path)
|
2238 |
+
output_path, result = extract_images_from_pdf(saved_pdf_path)
|
2239 |
print(" --------------------------------------- zip_path_str ---------------------------------------", output_path, result)
|
2240 |
# Check extracted_sprites.json for "scratch block" in any 'name'
|
2241 |
# extracted_dir = os.path.join(JSON_DIR, os.path.splitext(filename)[0])
|