| 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() |