"""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 "", '
❌ Please upload an image
'
try:
# Use pytesseract to extract text
text = pytesseract.image_to_string(Image.open(image))
if text.strip():
return text.strip(), '✅ Text extracted successfully
'
else:
return "", '❌ No text found in the image
'
except Exception as e:
return "", f'❌ Error extracting text: {str(e)}
'