prthm11 commited on
Commit
83178a6
·
verified ·
1 Parent(s): 5b568e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -2381,46 +2381,46 @@ def process_pdf():
2381
  # with open(extracted_sprites_json, 'r') as f:
2382
  # sprite_data = json.load(f)
2383
 
2384
- project_output = similarity_matching(output_path, project_folder)
2385
- logger.info("Received request to process PDF.")
2386
 
2387
- with open(project_output, 'r') as f:
2388
- project_skeleton = json.load(f)
2389
-
2390
 
2391
- images = convert_from_path(saved_pdf_path, dpi=300)
2392
- print(type)
2393
- page = images[0]
2394
- # img_base64 = base64.b64encode(images).decode("utf-8")
2395
- buf = BytesIO()
2396
- page.save(buf, format="PNG")
2397
- img_bytes = buf.getvalue()
2398
- img_b64 = base64.b64encode(img_bytes).decode("utf-8")
2399
  #image_paths = await convert_pdf_to_images_async(saved_pdf_path)
2400
 
2401
  #updating logic here [Dev Patel]
2402
- initial_state_dict = {
2403
- "project_json": project_skeleton,
2404
- "description": "The pseudo code for the script",
2405
- "project_id": project_id,
2406
- "project_image": img_b64,
2407
- "action_plan": {},
2408
- "pseudo_code": {},
2409
- "temporary_node": {},
2410
- }
2411
 
2412
- final_state_dict = app_graph.invoke(initial_state_dict) # Pass dictionary
2413
 
2414
- final_project_json = final_state_dict['project_json'] # Access as dict
2415
- #final_project_json = project_skeleton
2416
 
2417
  # Save the *final* filled project JSON, overwriting the skeleton
2418
- with open(project_output, "w") as f:
2419
- json.dump(final_project_json, f, indent=2)
2420
- logger.info(f"Final project JSON saved to {project_output}")
2421
 
2422
  # --- Call the new function to create the .sb3 file ---
2423
- sb3_file_path = create_sb3_archive(project_folder, project_id)
 
2424
 
2425
  if sb3_file_path:
2426
  logger.info(f"Successfully created SB3 file: {sb3_file_path}")
@@ -2435,7 +2435,8 @@ def process_pdf():
2435
  "output_json": "output_path",
2436
  "sprites": "result",
2437
  "project_output_json": "project_output",
2438
- "test_url": download_url
 
2439
  })
2440
  else:
2441
  return jsonify(error="Failed to create SB3 archive"), 500
 
2381
  # with open(extracted_sprites_json, 'r') as f:
2382
  # sprite_data = json.load(f)
2383
 
2384
+ # project_output = similarity_matching(output_path, project_folder)
2385
+ # logger.info("Received request to process PDF.")
2386
 
2387
+ # with open(project_output, 'r') as f:
2388
+ # project_skeleton = json.load(f)
 
2389
 
2390
+ # images = convert_from_path(saved_pdf_path, dpi=300)
2391
+ # print(type)
2392
+ # page = images[0]
2393
+ # # img_base64 = base64.b64encode(images).decode("utf-8")
2394
+ # buf = BytesIO()
2395
+ # page.save(buf, format="PNG")
2396
+ # img_bytes = buf.getvalue()
2397
+ # img_b64 = base64.b64encode(img_bytes).decode("utf-8")
2398
  #image_paths = await convert_pdf_to_images_async(saved_pdf_path)
2399
 
2400
  #updating logic here [Dev Patel]
2401
+ # initial_state_dict = {
2402
+ # "project_json": project_skeleton,
2403
+ # "description": "The pseudo code for the script",
2404
+ # "project_id": project_id,
2405
+ # "project_image": img_b64,
2406
+ # "action_plan": {},
2407
+ # "pseudo_code": {},
2408
+ # "temporary_node": {},
2409
+ # }
2410
 
2411
+ # final_state_dict = app_graph.invoke(initial_state_dict) # Pass dictionary
2412
 
2413
+ # final_project_json = final_state_dict['project_json'] # Access as dict
2414
+ # final_project_json = project_skeleton
2415
 
2416
  # Save the *final* filled project JSON, overwriting the skeleton
2417
+ # with open(project_output, "w") as f:
2418
+ # json.dump(final_project_json, f, indent=2)
2419
+ # logger.info(f"Final project JSON saved to {project_output}")
2420
 
2421
  # --- Call the new function to create the .sb3 file ---
2422
+ # sb3_file_path = create_sb3_archive(project_folder, project_id)
2423
+ sb3_file_path = BACKDROP_DIR #create_sb3_archive(project_folder, project_id)
2424
 
2425
  if sb3_file_path:
2426
  logger.info(f"Successfully created SB3 file: {sb3_file_path}")
 
2435
  "output_json": "output_path",
2436
  "sprites": "result",
2437
  "project_output_json": "project_output",
2438
+ # "test_url": download_url
2439
+ "test_url":r"https://prthm11-scratch-vision-game.hf.space/download_sb3/Event_test"
2440
  })
2441
  else:
2442
  return jsonify(error="Failed to create SB3 archive"), 500