Skip to content

Commit d95a8e6

Browse files
almost done
1 parent ffa0305 commit d95a8e6

File tree

16 files changed

+21
-3078
lines changed

16 files changed

+21
-3078
lines changed

.DS_Store

6 KB
Binary file not shown.

Backend/NotesToText.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import os
12
from fastapi import APIRouter
2-
3+
from pdf2image import convert_from_path
4+
from google.cloud import vision
35

46
# Create an instance of APIRouter
57
router = APIRouter()
@@ -22,21 +24,17 @@ def pdf_to_images(pdf_path, output_folder):
2224

2325
return image_paths,noImg
2426

25-
26-
27-
28-
substring_to_remove = "Scanned by CamScanner"
29-
3027
@router.get("/NotesToText")
3128
def NotesToText_handler():
32-
for i in range(1):
29+
substring_to_remove = "Scanned by CamScanner"
30+
for i in range(4):
3331
print(f"converting module-{i+1}....")
3432
pdf_path = f'Local_Storage/notes_pdf/module_{i+1}.pdf'
35-
output_folder = f'images/Notes_images'
33+
output_folder = f'images/Notes_images/module_{i+1}'
3634

3735
# Convert the PDF to images and save them in the output folder
3836
image_paths, noImg = pdf_to_images(pdf_path, output_folder)
39-
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'Files\Client_file_vision.json'
37+
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'Files/client_file_vision.json'
4038
client = vision.ImageAnnotatorClient()
4139

4240
# [START vision_python_migration_text_detection]
@@ -53,13 +51,14 @@ def NotesToText_handler():
5351
image_contents += text.replace(substring_to_remove, "")
5452

5553

56-
output_file = f"Local_Storage/notes_txt/module{i+1}.txt"
54+
output_file = f"Local_Storage/notes_txt/module_{i+1}.txt"
5755
# Write the text content to the output file
5856
with open(output_file, "w") as file:
5957
file.write(image_contents)
60-
58+
print(f"module-{i+1} completed")
59+
6160
if response.error.message:
62-
raise Exception(
61+
raise Exception(
6362
'{}\nFor more info on error messages, check: '
6463
'https://cloud.google.com/apis/design/errors'.format(
6564
response.error.message))
10 Bytes
Binary file not shown.
1.97 KB
Binary file not shown.
10 Bytes
Binary file not shown.
12 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)