typesdigital's picture
Update app.py
3169239
raw
history blame
604 Bytes
# app.py
import gradio as gr
from PIL import Image
import pytesseract
import numpy as np
def extract_text_from_image(image):
try:
# Convert the PIL image to a NumPy array
image_array = np.array(image)
# Use Tesseract to extract text
text = pytesseract.image_to_string(Image.fromarray(image_array))
return text
except Exception as e:
return str(e)
iface = gr.Interface(
fn=extract_text_from_image,
inputs=gr.Image(type="pil", label="Upload an image"),
outputs="text",
live=True,
)
if __name__ == "__main__":
iface.launch()