Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142import gradio as grfrom huggingface_hub import hf_hub_downloadfrom rapidocr_onnxruntime import RapidOCR
repo = "Rebeccaaaaaaaa/korean-handwriting-rec"
# Load the model and dictionary files directly from the repositoryengine = 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 interfacedemo = 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()app.pyAdded+42