File size: 649 Bytes
a342c8a
5cdda35
a342c8a
228de3b
a342c8a
5cdda35
 
 
 
 
 
 
 
a342c8a
5cdda35
 
 
 
 
 
a342c8a
5cdda35
a342c8a
5cdda35
228de3b
5cdda35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
import pytesseract
from PIL import Image
import io

def extract_text(file):
    if file is None:
        return "Please upload an invoice."
    
    image = Image.open(file.name)
    text = pytesseract.image_to_string(image)
    print(text)
    return text

with gr.Blocks() as demo:
    gr.Markdown("## Invoice OCR Extractor")
    
    with gr.Row():
        file_input = gr.File(label="Upload Invoice (PDF or Image)")
        extract_button = gr.Button("Extract Text")

    text_output = gr.Textbox(label="Extracted Text", lines=10)

    extract_button.click(extract_text, inputs=file_input, outputs=text_output)

demo.launch()