File size: 692 Bytes
4b0678e
 
c982cf8
4b0678e
c982cf8
 
 
39f86d4
c982cf8
 
 
 
 
 
 
 
 
 
 
4b0678e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
from pdf2image import convert_from_path
import pdfplumber

def convert_pdf_to_image(file):
    images = convert_from_path(file)
    return images

def extract_text_from_pdf(file):
    text = ""
    with pdfplumber.open(file) as pdf:
        for page in pdf.pages:
            text += page.extract_text()
    return text

pdf_to_img = gr.Interface(convert_pdf_to_image, gr.File(), gr.Gallery(), api_name="pdf_to_img")
pdf_to_text = gr.Interface(extract_text_from_pdf, gr.File(), gr.Textbox(placeholder="Extracted text will appear here"), api_name="pdf_to_text")

demo = gr.TabbedInterface([pdf_to_img, pdf_to_text], ["PDF to Image", "Extract Text"])
demo.launch(debug=True)