Update app.py
Browse files
app.py
CHANGED
|
@@ -2095,6 +2095,18 @@ def similarity_matching(sprites_data: str, project_folder: str) -> str:
|
|
| 2095 |
# # logger.info(f"🎉 Final project saved: {project_json_path}")
|
| 2096 |
# return project_json_path
|
| 2097 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2098 |
def delay_for_tpm_node(state: GameState):
|
| 2099 |
logger.info("--- Running DelayForTPMNode ---")
|
| 2100 |
time.sleep(60) # Adjust the delay as needed
|
|
@@ -2294,7 +2306,6 @@ def process_pdf():
|
|
| 2294 |
pdf_stream = io.BytesIO(pdf_bytes)
|
| 2295 |
logger.info(f"Saved uploaded PDF to: {pdf_stream}")
|
| 2296 |
|
| 2297 |
-
|
| 2298 |
# pdf= save_pdf_to_generated_dir(saved_pdf_path, project_id)
|
| 2299 |
pdf= save_pdf_to_generated_dir(pdf_stream, project_id)
|
| 2300 |
# logger.info(f"Created project folder: {project_folder}")
|
|
@@ -2326,15 +2337,18 @@ def process_pdf():
|
|
| 2326 |
with open(project_output, 'r') as f:
|
| 2327 |
project_skeleton = json.load(f)
|
| 2328 |
|
| 2329 |
-
images = convert_from_path(pdf_stream, dpi=300)
|
| 2330 |
-
print(type)
|
| 2331 |
-
page = images[0]
|
| 2332 |
-
# img_base64 = base64.b64encode(images).decode("utf-8")
|
| 2333 |
-
buf = BytesIO()
|
| 2334 |
-
page.save(buf, format="PNG")
|
| 2335 |
-
img_bytes = buf.getvalue()
|
| 2336 |
-
img_b64 = base64.b64encode(img_bytes).decode("utf-8")
|
| 2337 |
#image_paths = await convert_pdf_to_images_async(saved_pdf_path)
|
|
|
|
|
|
|
|
|
|
| 2338 |
|
| 2339 |
#updating logic here [Dev Patel]
|
| 2340 |
initial_state_dict = {
|
|
|
|
| 2095 |
# # logger.info(f"🎉 Final project saved: {project_json_path}")
|
| 2096 |
# return project_json_path
|
| 2097 |
|
| 2098 |
+
def convert_bytes_to_image(pdf_bytes: bytes, dpi: int):
|
| 2099 |
+
images = convert_from_bytes(pdf_bytes, dpi=dpi, poppler_path=poppler_path)
|
| 2100 |
+
# Save each page to an in-memory BytesIO and return a list of BytesIOs
|
| 2101 |
+
buffers = []
|
| 2102 |
+
for img in images:
|
| 2103 |
+
buf = BytesIO()
|
| 2104 |
+
img.save(buf, format="PNG")
|
| 2105 |
+
buf.seek(0)
|
| 2106 |
+
buffers.append(buf)
|
| 2107 |
+
return buffers
|
| 2108 |
+
|
| 2109 |
+
|
| 2110 |
def delay_for_tpm_node(state: GameState):
|
| 2111 |
logger.info("--- Running DelayForTPMNode ---")
|
| 2112 |
time.sleep(60) # Adjust the delay as needed
|
|
|
|
| 2306 |
pdf_stream = io.BytesIO(pdf_bytes)
|
| 2307 |
logger.info(f"Saved uploaded PDF to: {pdf_stream}")
|
| 2308 |
|
|
|
|
| 2309 |
# pdf= save_pdf_to_generated_dir(saved_pdf_path, project_id)
|
| 2310 |
pdf= save_pdf_to_generated_dir(pdf_stream, project_id)
|
| 2311 |
# logger.info(f"Created project folder: {project_folder}")
|
|
|
|
| 2337 |
with open(project_output, 'r') as f:
|
| 2338 |
project_skeleton = json.load(f)
|
| 2339 |
|
| 2340 |
+
# images = convert_from_path(pdf_stream, dpi=300)
|
| 2341 |
+
# print(type)
|
| 2342 |
+
# page = images[0]
|
| 2343 |
+
# # img_base64 = base64.b64encode(images).decode("utf-8")
|
| 2344 |
+
# buf = BytesIO()
|
| 2345 |
+
# page.save(buf, format="PNG")
|
| 2346 |
+
# img_bytes = buf.getvalue()
|
| 2347 |
+
# img_b64 = base64.b64encode(img_bytes).decode("utf-8")
|
| 2348 |
#image_paths = await convert_pdf_to_images_async(saved_pdf_path)
|
| 2349 |
+
|
| 2350 |
+
images = convert_bytes_to_image(pdf_stream)
|
| 2351 |
+
print("PDF converted to images:", images)
|
| 2352 |
|
| 2353 |
#updating logic here [Dev Patel]
|
| 2354 |
initial_state_dict = {
|