Spaces:
Sleeping
Sleeping
File size: 806 Bytes
f7892e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
"""Image processing and OCR services for ScriptVoice."""
import pytesseract
from PIL import Image
from typing import Tuple
def extract_text_from_image(image) -> Tuple[str, str]:
"""Extract text from uploaded image using OCR."""
if image is None:
return "", '<div class="status-error">β Please upload an image</div>'
try:
# Use pytesseract to extract text
text = pytesseract.image_to_string(Image.open(image))
if text.strip():
return text.strip(), '<div class="status-success">β
Text extracted successfully</div>'
else:
return "", '<div class="status-error">β No text found in the image</div>'
except Exception as e:
return "", f'<div class="status-error">β Error extracting text: {str(e)}</div>'
|