typesdigital's picture
Create app.py
49ae21d
raw
history blame
679 Bytes
# Install Tesseract and the pytesseract library
# Import necessary libraries
from PIL import Image
import pytesseract
import gradio as gr
# Define a function to extract text from an image
def extract_text_from_image(image_path):
try:
# Open the image file
img = Image.open(image_path)
# Use Tesseract to extract text
text = pytesseract.image_to_string(img)
return text
except Exception as e:
return str(e)
# Define Gradio interface
iface = gr.Interface(
fn=extract_text_from_image,
inputs=gr.Image(type="file", label="Upload an image"),
outputs="text"
)
# Launch Gradio interface
iface.launch(share=True)