slimshadow commited on
Commit
fa283a8
ยท
verified ยท
1 Parent(s): 599039a

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +34 -13
  2. app.py +30 -31
  3. apt.txt +2 -0
  4. requirements.txt +3 -3
README.md CHANGED
@@ -1,13 +1,34 @@
1
- ---
2
- title: Drawtotext
3
- emoji: ๐Ÿ“ˆ
4
- colorFrom: indigo
5
- colorTo: blue
6
- sdk: streamlit
7
- sdk_version: 1.35.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- # Configure Tesseract executable path if necessary
8
- pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract' # Adjust the path as needed
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.14.0
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