| import subprocess |
| import sys |
| import os |
|
|
| |
| |
| 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 |
|
|
| |
| easyocr_reader = easyocr.Reader(['en']) |
|
|
| def compare_ocr_models(image_path): |
| |
| easyocr_raw = easyocr_reader.readtext(image_path, detail=1) |
| easyocr_result = "" |
| for (bbox, text, conf) in easyocr_raw: |
| easyocr_result += f"{text} (Confidence: {round(conf * 100, 2)}%)\n" |
|
|
| |
| 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() |