Spaces:
Paused
Paused
Upload 4 files
Browse files
README.md
CHANGED
|
@@ -1,13 +1,34 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Drawtotext ๐
|
| 2 |
+
|
| 3 |
+
Convert drawings to text using Tesseract OCR.
|
| 4 |
+
|
| 5 |
+
## Metadata
|
| 6 |
+
- **Title**: Drawtotext
|
| 7 |
+
- **Emoji**: ๐
|
| 8 |
+
- **ColorFrom**: indigo
|
| 9 |
+
- **ColorTo**: blue
|
| 10 |
+
- **SDK**: streamlit
|
| 11 |
+
- **SDK Version**: 1.35.0
|
| 12 |
+
- **App File**: app.py
|
| 13 |
+
- **Pinned**: false
|
| 14 |
+
- **License**: MIT
|
| 15 |
+
|
| 16 |
+
## How to Run
|
| 17 |
+
|
| 18 |
+
1. Install dependencies:
|
| 19 |
+
```bash
|
| 20 |
+
pip install -r requirements.txt
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
2. Create `apt.txt` with the following content:
|
| 24 |
+
```
|
| 25 |
+
tesseract-ocr
|
| 26 |
+
libtesseract-dev
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
3. Run the app:
|
| 30 |
+
```bash
|
| 31 |
+
streamlit run app.py
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
4. Ensure Tesseract OCR is installed and properly configured.
|
app.py
CHANGED
|
@@ -1,31 +1,30 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from streamlit_drawable_canvas import st_canvas
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import pytesseract
|
| 5 |
-
import numpy as np
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
pytesseract.pytesseract.tesseract_cmd =
|
| 9 |
-
|
| 10 |
-
st.title("Handwritten Text Recognition")
|
| 11 |
-
|
| 12 |
-
# Create a canvas component
|
| 13 |
-
canvas_result = st_canvas(
|
| 14 |
-
fill_color="rgba(255, 165, 0, 0.3)", # Fill color with some transparency
|
| 15 |
-
stroke_width=2,
|
| 16 |
-
stroke_color="#000000",
|
| 17 |
-
background_color="#ffffff",
|
| 18 |
-
update_streamlit=True,
|
| 19 |
-
height=150,
|
| 20 |
-
width=600,
|
| 21 |
-
drawing_mode="freedraw",
|
| 22 |
-
key="canvas"
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
# Process the canvas image
|
| 26 |
-
if canvas_result.image_data is not None:
|
| 27 |
-
img = Image.fromarray(canvas_result.image_data.astype('uint8'), 'RGBA').convert('L')
|
| 28 |
-
img = img.resize((img.width * 2, img.height * 2), Image.LANCZOS) # Resize to improve OCR accuracy
|
| 29 |
-
text = pytesseract.image_to_string(img, config='--psm 6')
|
| 30 |
-
st.text_area("Recognized Text", text, height=100)
|
| 31 |
-
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_drawable_canvas import st_canvas
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import pytesseract
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Set the path to the Tesseract executable for Hugging Face Spaces
|
| 8 |
+
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
|
| 9 |
+
|
| 10 |
+
st.title("Handwritten Text Recognition")
|
| 11 |
+
|
| 12 |
+
# Create a canvas component
|
| 13 |
+
canvas_result = st_canvas(
|
| 14 |
+
fill_color="rgba(255, 165, 0, 0.3)", # Fill color with some transparency
|
| 15 |
+
stroke_width=2,
|
| 16 |
+
stroke_color="#000000",
|
| 17 |
+
background_color="#ffffff",
|
| 18 |
+
update_streamlit=True,
|
| 19 |
+
height=150,
|
| 20 |
+
width=600,
|
| 21 |
+
drawing_mode="freedraw",
|
| 22 |
+
key="canvas"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Process the canvas image
|
| 26 |
+
if canvas_result.image_data is not None:
|
| 27 |
+
img = Image.fromarray(canvas_result.image_data.astype('uint8'), 'RGBA').convert('L')
|
| 28 |
+
img = img.resize((img.width * 2, img.height * 2), Image.LANCZOS) # Resize to improve OCR accuracy
|
| 29 |
+
text = pytesseract.image_to_string(img, config='--psm 6')
|
| 30 |
+
st.text_area("Recognized Text", text, height=100)
|
|
|
apt.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tesseract-ocr
|
| 2 |
+
libtesseract-dev
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
streamlit==1.
|
| 2 |
-
streamlit-drawable-canvas==0.8.0
|
| 3 |
-
pytesseract==0.3.10
|
| 4 |
Pillow==9.1.0
|
|
|
|
| 1 |
+
streamlit==1.35.0
|
| 2 |
+
streamlit-drawable-canvas==0.8.0
|
| 3 |
+
pytesseract==0.3.10
|
| 4 |
Pillow==9.1.0
|