Spaces:
Paused
Paused
File size: 1,029 Bytes
fa283a8 |
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 streamlit as st
from streamlit_drawable_canvas import st_canvas
from PIL import Image
import pytesseract
import numpy as np
# Set the path to the Tesseract executable for Hugging Face Spaces
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
st.title("Handwritten Text Recognition")
# Create a canvas component
canvas_result = st_canvas(
fill_color="rgba(255, 165, 0, 0.3)", # Fill color with some transparency
stroke_width=2,
stroke_color="#000000",
background_color="#ffffff",
update_streamlit=True,
height=150,
width=600,
drawing_mode="freedraw",
key="canvas"
)
# Process the canvas image
if canvas_result.image_data is not None:
img = Image.fromarray(canvas_result.image_data.astype('uint8'), 'RGBA').convert('L')
img = img.resize((img.width * 2, img.height * 2), Image.LANCZOS) # Resize to improve OCR accuracy
text = pytesseract.image_to_string(img, config='--psm 6')
st.text_area("Recognized Text", text, height=100)
|