Spaces:
Build error
Build error
Update app.py
#1
by Soumen - opened
31 unmodified lines323334353637382 unmodified lines4142434445462 unmodified lines495051525354555657585960616244 unmodified lines10710810911011111211331 unmodified linesfrom PIL import Imagefrom PyPDF2 import PdfFileReaderimport pdfplumber# NLP Pkgsfrom textblob import TextBlobimport spacy2 unmodified linesimport cv2import numpy as npimport pytesseract#pytesseract.pytesseract.tesseract_cmd = r"./Tesseract-OCR/tesseract.exe"from PIL import Imagedef read_pdf(file):2 unmodified linesall_page_text = ""for i in range(count):page = pdfReader.getPage(i)all_page_text += page.extractText()return all_page_text#def read_pdf_with_pdfplumber(file):# with pdfplumber.open(file) as pdf:# page = pdf.pages[0]# return page.extract_text()sst.title("Streamlit NLP APP")@st.experimental_singletondef text_analyzer(my_text):44 unmodified linesimg = Image.open(uploaded_photo)img = img.save("img.png")img = cv2.imread("img.png")text = pytesseract.image_to_string(img, lang="ben") if st.checkbox("Mark to see Bangla Image's Text") else pytesseract.image_to_string(img)st.success(text)elif camera_photo:img = Image.open(camera_photo)31 unmodified lines323334353637382 unmodified lines414243444546472 unmodified lines505152535455565758596061626364656644 unmodified lines11111211311411511611711811912012112212312412512612712831 unmodified linesfrom PIL import Imagefrom PyPDF2 import PdfFileReaderimport pdfplumberfrom line_cor import mark_region# NLP Pkgsfrom textblob import TextBlobimport spacy2 unmodified linesimport cv2import numpy as npimport pytesseract#pytesseract.pytesseract.tesseract_cmd = r"./Tesseract-OCR/tesseract.exe"from PIL import Imagedef read_pdf(file):2 unmodified linesall_page_text = ""for i in range(count):page = pdfReader.getPage(i)image_name = "Page_" + str(i) + ".jpg"page.save(image_name, "JPEG")text = pytesseract.image_to_string(image_name, lang="ben") if st.checkbox("Mark to see Bangla Image's Text") else pytesseract.image_to_string(image_name)all_page_text += text + " " #page.extractText()return all_page_text#def read_pdf_with_pdfplumber(file):# with pdfplumber.open(file) as pdf:# page = pdf.pages[0]# return page.extract_text()st.title("Streamlit NLP APP")@st.experimental_singletondef text_analyzer(my_text):44 unmodified linesimg = Image.open(uploaded_photo)img = img.save("img.png")img = cv2.imread("img.png")# get co-ordinates to crop the imageimage, lc = mark_region(img)c = lc[1]# cropping image img = image[y0:y1, x0:x1]img = image[c[0][1]:c[1][1], c[0][0]:c[1][0]]plt.figure(figsize=(10,10))plt.imshow(img)# convert the image to black and white for better OCRret,thresh1 = cv2.threshold(img,120,255,cv2.THRESH_BINARY)# pytesseract image to string to get resultstext = str(pytesseract.image_to_string(thresh1, config='--psm 6',lang="ben")) if st.checkbox("Bangla") else str(pytesseract.image_to_string(thresh1, config='--psm 6'))#text = pytesseract.image_to_string(img, lang="ben") if st.checkbox("Mark to see Bangla Image's Text") else pytesseract.image_to_string(img)st.success(text)elif camera_photo:img = Image.open(camera_photo)
app.py+19-4