theoracle/easyocr-api
0
1import gradio as gr2import easyocr3import numpy as np4from PIL import Image5import torch6import spaces7 8 9# Declare reader outside the function (only once)10 11 12@spaces.GPU # Ensures this function runs on GPU13def extract_text(image):14 reader = easyocr.Reader(['en'], gpu=True)15 result = reader.readtext(np.array(image), detail=0)16 text = "\n".join(result)17 print("OCR complete. Text:", text)18 return text19 20iface = gr.Interface(21 fn=extract_text,22 inputs=gr.Image(type="pil"),23 outputs="text",24 title="GPU OCR with EasyOCR",25 description="Upload an image. OCR runs on GPU using EasyOCR + Hugging Face Spaces."26)27 28iface.launch()29 