File size: 1,559 Bytes
cba12ba 1a3aefe b87dd61 cba12ba b87dd61 cba12ba 1a3aefe cba12ba 75d6263 cba12ba 94d9e98 | 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import subprocess
import sys
import os
# Fine-tuned OCR Installation
# Install the .whl only if not already done
if not os.path.exists("fine_tuned_ocr_installed.txt"):
subprocess.check_call([
sys.executable, "-m", "pip", "install", "packages/fine_tuned_ocr-0.2.0-py3-none-any.whl"
])
with open("fine_tuned_ocr_installed.txt", "w") as f:
f.write("installed")
import gradio as gr
from fine_tuned_ocr import fine_tuned_ocr
import easyocr
# Initialize EasyOCR Reader
easyocr_reader = easyocr.Reader(['en'])
def compare_ocr_models(image_path):
# --- EasyOCR Prediction ---
easyocr_raw = easyocr_reader.readtext(image_path, detail=1) # Get text + confidence
easyocr_result = ""
for (bbox, text, conf) in easyocr_raw:
easyocr_result += f"{text} (Confidence: {round(conf * 100, 2)}%)\n"
# --- Fine-tuned OCR Prediction ---
ft_text, ft_conf = fine_tuned_ocr(image_path)
fine_tuned_result = f"{ft_text} (Confidence: {round(ft_conf * 100, 2)}%)\n"
return easyocr_result.strip(), fine_tuned_result.strip()
examples = [
["samples/sample1.png"],
["samples/sample2.png"]
]
demo = gr.Interface(
fn=compare_ocr_models,
inputs=gr.Image(type="filepath", label="Upload Image"),
outputs=[
gr.Textbox(label="EasyOCR Output"),
gr.Textbox(label="Fine-tuned OCR Output")
],
title="🔎 OCR Comparison App",
description="Compare OCR results from EasyOCR and a fine-tuned custom OCR model.",
examples=examples
)
if __name__ == "__main__":
demo.launch() |