Spaces:
Runtime error
Runtime error
File size: 878 Bytes
4aa5de4 |
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 30 31 |
import gradio as gr
import pytesseract
from PIL import Image
import os
def extract_text(image_path):
if not image_path:
return "No image uploaded. Please upload an image."
if not os.path.exists(image_path):
return f"Error: File not found at {image_path}"
try:
img = Image.open(image_path)
text = pytesseract.image_to_string(img)
return text if text.strip() else "No text detected in the image."
except Exception as e:
return f"An error occurred: {str(e)}"
# Create the Gradio interface (same as before)
iface = gr.Interface(
fn=extract_text,
inputs=gr.Image(type="filepath", label="Upload an image"),
outputs=gr.Textbox(label="Extracted Text"),
title="Image Text Extractor",
description="Upload an image and extract text from it using OCR."
)
# Launch the interface
iface.launch()
|