Update app.py
Browse files
app.py
CHANGED
|
@@ -2248,6 +2248,36 @@ def create_sb3_archive(project_folder, project_id):
|
|
| 2248 |
os.remove(sb3_path)
|
| 2249 |
return sb3_path
|
| 2250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2251 |
|
| 2252 |
@app.route('/')
|
| 2253 |
def index():
|
|
@@ -2307,9 +2337,10 @@ def process_pdf():
|
|
| 2307 |
saved_pdf_path = os.path.join(temp_dir, filename)
|
| 2308 |
pdf_file.save(saved_pdf_path)
|
| 2309 |
pdf_doc = saved_pdf_path
|
|
|
|
| 2310 |
# logger.info(f"Created project folder: {project_folder}")
|
| 2311 |
logger.info(f"Saved uploaded PDF to: {saved_pdf_path}")
|
| 2312 |
-
logger.info(f"Saved uploaded PDF to: {pdf_file}")
|
| 2313 |
print("--------------------------------pdf_file_path---------------------",pdf_file,saved_pdf_path)
|
| 2314 |
# Extract & process
|
| 2315 |
# output_path, result = extract_images_from_pdf(saved_pdf_path, json_path)
|
|
@@ -2365,6 +2396,7 @@ def process_pdf():
|
|
| 2365 |
|
| 2366 |
# --- Call the new function to create the .sb3 file ---
|
| 2367 |
sb3_file_path = create_sb3_archive(project_folder, project_id)
|
|
|
|
| 2368 |
if sb3_file_path:
|
| 2369 |
logger.info(f"Successfully created SB3 file: {sb3_file_path}")
|
| 2370 |
# Instead of returning the local path, return a URL to the download endpoint
|
|
|
|
| 2248 |
os.remove(sb3_path)
|
| 2249 |
return sb3_path
|
| 2250 |
|
| 2251 |
+
def save_pdf_to_generated_dir(pdf_path: str, project_id: str) -> str:
|
| 2252 |
+
"""
|
| 2253 |
+
Copies the PDF at `pdf_path` into GEN_PROJECT_DIR/project_id/,
|
| 2254 |
+
renaming it to <project_id>.pdf.
|
| 2255 |
+
|
| 2256 |
+
Args:
|
| 2257 |
+
pdf_path (str): Any existing path to a PDF file.
|
| 2258 |
+
project_id (str): Your unique project identifier.
|
| 2259 |
+
|
| 2260 |
+
Returns:
|
| 2261 |
+
str: Path to the copied PDF in the generated directory,
|
| 2262 |
+
or None if something went wrong.
|
| 2263 |
+
"""
|
| 2264 |
+
try:
|
| 2265 |
+
# 1) Build the destination directory and base filename
|
| 2266 |
+
output_dir = GEN_PROJECT_DIR / project_id
|
| 2267 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 2268 |
+
|
| 2269 |
+
# 2) Define the target PDF path
|
| 2270 |
+
target_pdf = output_dir / f"{project_id}.pdf"
|
| 2271 |
+
|
| 2272 |
+
# 3) Copy the PDF
|
| 2273 |
+
shutil.copy2(pdf_path, target_pdf)
|
| 2274 |
+
logger.info(f"Copied PDF from {pdf_path} → {target_pdf}")
|
| 2275 |
+
|
| 2276 |
+
return str(target_pdf)
|
| 2277 |
+
|
| 2278 |
+
except Exception as e:
|
| 2279 |
+
logger.error(f"Failed to save PDF to generated dir: {e}", exc_info=True)
|
| 2280 |
+
return None
|
| 2281 |
|
| 2282 |
@app.route('/')
|
| 2283 |
def index():
|
|
|
|
| 2337 |
saved_pdf_path = os.path.join(temp_dir, filename)
|
| 2338 |
pdf_file.save(saved_pdf_path)
|
| 2339 |
pdf_doc = saved_pdf_path
|
| 2340 |
+
pdf= save_pdf_to_generated_dir(saved_pdf_path, project_id)
|
| 2341 |
# logger.info(f"Created project folder: {project_folder}")
|
| 2342 |
logger.info(f"Saved uploaded PDF to: {saved_pdf_path}")
|
| 2343 |
+
logger.info(f"Saved uploaded PDF to: {pdf_file}: {pdf}")
|
| 2344 |
print("--------------------------------pdf_file_path---------------------",pdf_file,saved_pdf_path)
|
| 2345 |
# Extract & process
|
| 2346 |
# output_path, result = extract_images_from_pdf(saved_pdf_path, json_path)
|
|
|
|
| 2396 |
|
| 2397 |
# --- Call the new function to create the .sb3 file ---
|
| 2398 |
sb3_file_path = create_sb3_archive(project_folder, project_id)
|
| 2399 |
+
|
| 2400 |
if sb3_file_path:
|
| 2401 |
logger.info(f"Successfully created SB3 file: {sb3_file_path}")
|
| 2402 |
# Instead of returning the local path, return a URL to the download endpoint
|