import streamlit as st
from PyPDF2 import PdfReader
from concurrent.futures import ThreadPoolExecutor
from base64 import b64encode
from fpdf import FPDF
import io, string, re, math
from io import StringIO
# Importing the Fastify Class
from fast_reader import Fastify_Reader
def pdf_extract_text(pdf_docs):
'''
Basic function for extracting text from the PDFs
'''
text = ""
for pdf in pdf_docs:
pdf_reader = PdfReader(pdf)
for page in pdf_reader.pages:
text += page.extract_text()
return text
def text_to_pdf_fastify(text):
bold_text = Fastify_Reader(text).fastify()
bold_text = bold_text.encode('latin-1', 'ignore').decode('latin-1')
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size = 12)
pdf.multi_cell(0, 10, txt = bold_text, markdown=True)
return bytes(pdf.output())
def text_to_pdf(text):
text = text.encode('latin-1', 'ignore').decode('latin-1')
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size = 12)
pdf.multi_cell(0, 10, txt = text, markdown=True)
return bytes(pdf.output())
st.set_page_config(page_title="Fastify Reader",
page_icon=":books:",
layout="wide")
with st.sidebar:
st.image("Logo.jpg")
st.markdown("
How fast can you read really?
", unsafe_allow_html=True)
tab1, tab2= st.tabs(["PDF file", "Input Text"])
with tab1:
st.header("PDF File")
uploaded_file = st.file_uploader("Upload a PDF file", type="pdf", accept_multiple_files=True)
if st.button("Submit", key="pdf"):
with st.spinner("Processing"):
text = pdf_extract_text(uploaded_file)
original_pdf = b64encode(text_to_pdf(text)).decode("utf-8")
base64_pdf = b64encode(text_to_pdf_fastify(text)).decode("utf-8")
original_display = f'