Некоторые другие варианты, которые я пробовал ниже:
Код: Выделить всё
pdfplumber: import pandas as pd import pdfplumber path = r"my_pdf_file.pdf" data = [] with pdfplumber.open(path) as pdf: pages = pdf.pages for p in pages: data.append(p.extract_tables()) print(data)Код: Выделить всё
with pdfplumber.open(path) as pdf: first_page = pdf.pages[0] first_page.to_image()
С помощью приведенного ниже кода я могу извлечь только верхнюю часть личной информации, но не необходимые результаты тестов, которые разделены большим количеством пробелов.Код: Выделить всё
data[0][0][0][0].splitlines()по сути, это может дать мне только приведенный выше контейнерный раздел PDF, а не приведенные ниже необходимые данные, которые разделены большим количеством пробелов:Код: Выделить всё
['Patient Name : Mr.VINEET', 'Age/Sex : 39 YRS/M Lab Id. : 012408030006', 'Refered By : Self Sample Collection On : 03/Aug/2024 08:30AM', 'Collected By : HARPREET Sample Lab Rec.On : 03/Aug/2024 11:50 AM', 'Collection Mode : HOME COLLECTION Reporting On : 03/Aug/2024 03:24 PM', 'BarCode : 10593974']Код: Выделить всё
pages.to_image().debug_tablefinder()
выход:Код: Выделить всё
PdfReader: this also gives only text format and nothing structured from pypdf import PdfReader reader = PdfReader(path) reader.pages[0].extract_text().splitlines()Даже это не дает никаких табличных данных.Код: Выделить всё
['NEW AAROGYA EXECUTIVE PACKAGE 108 TEST', 'Kidney Function Test (KFT),Serum', 'BLOOD UREA', '(Method : Urease-GLDH)31.80 12-43 mg/dL', 'BLOOD UREA NITROGEN (BUN)', '(Method : Calculated)15 6 - 21 mg/dl', 'SERUM CREATININE', '(Method : Modified Jaffe,s)1.10 0.9 - 1.3 mg/dL', ' ', 'Creatinine is a by product of muscle catabolism. It is filtered by kidney and excreted in the urine. if the filtering of the kidney is deficient, creatinine levels in blood are', 'increased.', ' ', 'Creatine level is used for the assessment of kidney function and to diagnose renal dysfunction. However, more important than absolute creatinine level is the trend of', 'serum creatinine levels over time. Serum creatine is especially useful in evaluation of glomerular function. BUN (Blood Urea Nitrogen) & Creatine are frequently', 'compared. If BUN increased and creatinine is normal, dehydration is present; and if both increased, then renal disorder is present.', ' ', 'Conditions associated with increased creatine level : Acute and chronic renal failure, shock (prolonged), systemic lupus erythematosis, cancer, leukemia ,', 'hypertension, acute myocardial infaction, diabetic nephropathy , diet rich in creatinine (e.g. beef), congenital renal disease etc. ', 'Condition associated with decreased creatine level : Pregnancy, Eclampsia etc.', ' ', 'Opinion & Advice:', 'People with increased creatine levels are advised to undergo : Kidney Function Test, Urine Examination & USG (Whole abdomen) at regular intervals.', 'Decreased creatine levels are usually insignificant.', 'SERUM URIC ACID', '(Method : Uricase-POD)5.8 3.5-7.2 mg/dL', 'UREA / CREATININE RATIO', '(Method : Calculated)28.91 23 - 33 Ratio', 'BUN / CREATININE RATIO', '(Method : Calculated)13.51 5.5 - 19.2 Ratio', 'INORGANIC PHOSPHORUS', '(Method : UV Molybdate)3.63 2.5-4.5 mg/dL',Код: Выделить всё
pytesseract: import os from PIL import Image import pdf2image from pdf2image import convert_from_path import pytesseractКод: Выделить всё
img = Image.open(r"saved_image.png")выход:Код: Выделить всё
text = pytesseract.image_to_string(img) textпример вывода из приведенной выше строки:Код: Выделить всё
'OF tata\n\nOe\n\nLABORATORY TEST REPORT\n\nPatient Name >Mr.VINEET\n\nAge/Sex :39 YRS/M Lab Id. : 012408030006\nRefered By : Self Sample Collection On : 03/Aug/2024 08:30AM\n\nCollected By > HARPREET Sample Lab Rec.On : 03/Aug/2024 11:50 AM\nCollection Mode :HOME COLLECTION Reporting On : 03/Aug/2024 03:24 PM\nBarCode : 10593974\n\nTest Name Result Biological Ref. Int. Unit\n\nNEW AAROGYA EXECUTIVE PACKAGE 108 TEST\nKidney Function Test (KFT),Serum\n\nBLOOD UREA 31.80 12-43 mg/dL\n(Method ; Urease-GLDH)\n\nBLOOD UREA NITROGEN (BUN) 15 6-21 mg/dl\n(Method : Calculated)\n\nSERUM CREATININE 1.10 0.9-1.3 mg/dL\n\n(Method : Modified Jaffe,s)\n\nCreatinine is a by product of muscle catabolism. It is filtered by kidney and excreted in the urine. if the filtering of the kidney is deficient, creatinine levels in blood are\nincreased.\n\nCreatine level is used for the assessment of kidney function and to diagnose renal dysfunction. However, more important than absolute creatinine level is the trend of\nserum creatinine levels over time. Serum creatine is especially useful in evaluation of glomerular function. BUN (Blood Urea Nitrogen) & Creatine are frequently\ncompared. If BUN increased and creatinine is normal, dehydration Is present; and if both increased, then renal disorder is present.\n\nConditions associated with increased creatine level : Acute and chronic renal failure, shock (prolonged), systemic lupus erythematosis, cancer, leukemia ,\nhypertension, acute myocardial infaction, diabetic nephropathy , diet rich in creatinine (e.g. beef), congenital renal disease etc.\nCondition associated with decreased creatine level : Pregnancy, Eclampsia etc.\n\nOpinion & Advice:\nPeople with increased creatine levels are advised to undergo : Kidney Function Test, Urine Examination & USG (Whole abdomen) at regular intervals.\nDecreased creatine levels are usually insignificant.\n\nSERUM URIC ACID 5.8 3.5-7.2 mg/dL\n(Method : Uricase-POD)\n\nUREA / CREATININE RATIO 28.91 23-33 Ratio\n(Method : Calculated)\n\nBUN / CREATININE RATIO 13.51 5.5- 19.2 Ratio\n(Method : Calculated)\n\nINORGANIC PHOSPHORUS 3.63 2.5-4.5 mg/dL\n\n(Method : UV Molybdate)\n\na\n\n5 SS\n.—— =\n\nDR. ASHOK MALHOTRA DR. SANJEEV R. SAIGAL DR. B. JUNEJA |\nMBBS, MD (BIOCHEMISTRY) PHD (MEDICAL MICROBIOLOGY) MBBS, MD (PATHOLOGY)\n\nCONDITIONS OF REPORTING\n\ni) «) @) @)\n\nThe reported results are for information and for interpretation of the referring doctor only. 3 It is presumed that the tests performed on the specimen belong to the patient named or identified.\nResults of the tests may vary from laboratory to laboratory and also in some parameters from time to time forthe same patient 2 Should the results indicate an unexpected abnormally, the same should be reconfirmed.\nOnly such medical professionals who understand reporting units, reference ranges and limitations of technologies should interpret results. =< This report is not valid for medicotegal purposes.\n\nPage 1 of 20\n\nNeither Aarogya Pathcare, nor its employees / representatives assume any liability, responsibility for any loss or damages that may be incurred by any person as a result of persuming the meaning or contents of the r\n\nSUGGESTIONS\nValues out of reference range requires reconfirmation before starting any medical treatments. 3 Retesting is needed if you suspect any quality shotcomings. = Testing or retesting should be done iin accredited laboratories. 2 ff any complaint / Suggestion call : 7627957531, 7011346653\n\n7\nol\n\n'Код: Выделить всё
n\nBLOOD UREA NITROGEN (BUN) 15 6-21 mg/dl\n(Method : Calculated)\n\nSERUM CREATININE 1.10 0.9-1.3 mg/dL\n\n
Код: Выделить всё
BLOOD UREA NITROGEN (BUN)|15|6-21|mg/dl
(Method : Calculated)
SERUM CREATININE|1.10|0.9-1.3|mg/dL
То же самое, что я смог сделать с помощью Llama_Parse, но я не могу использовать это в Streamlit, поэтому ищу альтернативы. Поэтому мне нужно решение на Python без моделей искусственного интеллекта, таких как Llama_parse.
Подробнее здесь: https://stackoverflow.com/questions/790 ... to-a-colum