| import os |
| |
| |
| |
| |
| |
| import gradio as gr |
| from PIL import Image |
| import pytesseract |
|
|
|
|
|
|
| class OCR: |
| def __init__(self, image_path): |
| self.image = image_path |
|
|
| def extract_text(self): |
| |
| text = pytesseract.image_to_string(self.image, lang="eng") |
| os.remove(self.image) |
| return text |
|
|
|
|
| def run_ocr(image_path: str) -> str: |
| |
| |
| ocr_engine = OCR(image_path=image_path) |
| return ocr_engine.extract_text() |
|
|
|
|
| def run(): |
| demo = gr.Interface( |
| fn=run_ocr, |
| inputs=gr.Image(type="filepath"), |
| outputs=gr.Textbox(label="Extracted Text"), |
| title="OCR Demo (pytesseract)" |
| ) |
|
|
| demo.launch( |
| |
| |
| share=True |
| |
| ) |
|
|
| if __name__ == "__main__": |
| run() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|