Spaces:
Sleeping
Sleeping
File size: 654 Bytes
2c24fb1 ec903c3 2c24fb1 ec903c3 2c24fb1 |
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 |
import gradio as gr
import easyocr
import numpy as np
from PIL import Image
import torch
import spaces
# Declare reader outside the function (only once)
@spaces.GPU # Ensures this function runs on GPU
def extract_text(image):
reader = easyocr.Reader(['en'], gpu=True)
result = reader.readtext(np.array(image), detail=0)
text = "\n".join(result)
print("OCR complete. Text:", text)
return text
iface = gr.Interface(
fn=extract_text,
inputs=gr.Image(type="pil"),
outputs="text",
title="GPU OCR with EasyOCR",
description="Upload an image. OCR runs on GPU using EasyOCR + Hugging Face Spaces."
)
iface.launch()
|