Spaces:
Running

req / app.py
riaz478's picture
Create app.py
1bda2f0 verified
Raw History Blame Contribute Delete
1.19 kB
import gradio as gr
from huggingface_hub import hf_hub_download
from rapidocr_onnxruntime import RapidOCR
repo = "Rebeccaaaaaaaa/korean-handwriting-rec"
# Load the model and dictionary files directly from the repository
engine = RapidOCR(
params={
"Rec.model_path": hf_hub_download(repo, "model/rec_korean_hw.onnx"),
"Rec.rec_keys_path": hf_hub_download(repo, "model/ppocrv5_korean_dict.txt"),
}
)
def recognize_korean(image):
if image is None:
return "Please upload an image."
# Perform OCR on the uploaded image
result, _ = engine(image)
if result:
# Join all detected text lines
return "\n".join([line[1] for line in result])
return "No text detected."
# Create a Gradio web interface
demo = gr.Interface(
fn=recognize_korean,
inputs=gr.Image(type="filepath", label="Upload Korean Handwriting Image"),
outputs=gr.Textbox(label="Recognized Text"),
title="Korean Handwriting OCR",
description=(
"Upload an image containing Korean handwriting or printed documents to"
" extract text using the fine-tuned PP-OCRv5 model."
),
)
if __name__ == "__main__":
demo.launch()