prthm11 commited on
Commit
8a9cf86
·
verified ·
1 Parent(s): 05ec958

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -62,7 +62,7 @@ pytesseract.pytesseract.tesseract_cmd = (r'/usr/bin/tesseract')
62
  # This is crucial for Tesseract to find its language data files (e.g., eng.traineddata)
63
  # os.environ['TESSDATA_PREFIX'] = r'C:\Program Files\Tesseract-OCR'
64
 
65
- poppler_path = r"C:\poppler\Library\bin"
66
  backdrop_images_path = r"blocks\Backdrops"
67
  sprite_images_path = r"blocks\sprites"
68
 
@@ -1072,7 +1072,7 @@ def create_sb3_archive(project_folder, project_id):
1072
  Returns:
1073
  str: The path to the created .sb3 file, or None if an error occurred.
1074
  """
1075
- output_filename = os.path.join("generated_projects", project_id)
1076
  zip_path = None
1077
  sb3_path = None
1078
  try:
@@ -1179,8 +1179,14 @@ def process_pdf():
1179
  project_skeleton = json.load(f)
1180
 
1181
 
1182
- images = convert_from_path(saved_pdf_path, dpi=300, poppler_path=poppler_path)
1183
- img_base64 = base64.b64encode(images).decode("utf-8")
 
 
 
 
 
 
1184
  #image_paths = await convert_pdf_to_images_async(saved_pdf_path)
1185
 
1186
  #updating logic here [Dev Patel]
@@ -1188,7 +1194,7 @@ def process_pdf():
1188
  "project_json": project_skeleton,
1189
  "description": "The pseudo code for the script",
1190
  "project_id": project_id,
1191
- "project_image": img_base64,
1192
  "action_plan": {},
1193
  "pseudo_code": {},
1194
  "temporary_node": {},
@@ -1208,7 +1214,7 @@ def process_pdf():
1208
  if sb3_file_path:
1209
  logger.info(f"Successfully created SB3 file: {sb3_file_path}")
1210
  # Instead of returning the local path, return a URL to the download endpoint
1211
- download_url = f"/download_sb3/{project_id}"
1212
  return jsonify({"message": "Procesed PDF and Game sb3 generated successfully", "project_id": project_id, "download_url": download_url})
1213
  else:
1214
  return jsonify(error="Failed to create SB3 archive"), 500
 
62
  # This is crucial for Tesseract to find its language data files (e.g., eng.traineddata)
63
  # os.environ['TESSDATA_PREFIX'] = r'C:\Program Files\Tesseract-OCR'
64
 
65
+ # poppler_path = r"C:\poppler\Library\bin"
66
  backdrop_images_path = r"blocks\Backdrops"
67
  sprite_images_path = r"blocks\sprites"
68
 
 
1072
  Returns:
1073
  str: The path to the created .sb3 file, or None if an error occurred.
1074
  """
1075
+ output_filename = os.path.join("outputs", project_id)
1076
  zip_path = None
1077
  sb3_path = None
1078
  try:
 
1179
  project_skeleton = json.load(f)
1180
 
1181
 
1182
+ images = convert_from_path(saved_pdf_path, dpi=300)
1183
+ print(type)
1184
+ page = images[0]
1185
+ # img_base64 = base64.b64encode(images).decode("utf-8")
1186
+ buf = BytesIO()
1187
+ page.save(buf, format="PNG")
1188
+ img_bytes = buf.getvalue()
1189
+ img_b64 = base64.b64encode(img_bytes).decode("utf-8")
1190
  #image_paths = await convert_pdf_to_images_async(saved_pdf_path)
1191
 
1192
  #updating logic here [Dev Patel]
 
1194
  "project_json": project_skeleton,
1195
  "description": "The pseudo code for the script",
1196
  "project_id": project_id,
1197
+ "project_image": img_b64,
1198
  "action_plan": {},
1199
  "pseudo_code": {},
1200
  "temporary_node": {},
 
1214
  if sb3_file_path:
1215
  logger.info(f"Successfully created SB3 file: {sb3_file_path}")
1216
  # Instead of returning the local path, return a URL to the download endpoint
1217
+ download_url = f"https://prthm11-scratch-vlm-v1.hf.space//download_sb3//{project_id}"
1218
  return jsonify({"message": "Procesed PDF and Game sb3 generated successfully", "project_id": project_id, "download_url": download_url})
1219
  else:
1220
  return jsonify(error="Failed to create SB3 archive"), 500