Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import pytesseract
|
|
|
4 |
|
5 |
-
# Explicitly set
|
6 |
-
|
|
|
7 |
|
8 |
st.set_page_config(page_title="Image to Text OCR", layout="centered")
|
9 |
|
@@ -18,10 +20,14 @@ if uploaded_file is not None:
|
|
18 |
|
19 |
if st.button("Extract Text"):
|
20 |
with st.spinner("Extracting text..."):
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
else:
|
25 |
st.info("Please upload an image to get started.")
|
26 |
|
27 |
|
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import pytesseract
|
4 |
+
import os
|
5 |
|
6 |
+
# Explicitly set Tesseract path, especially for Hugging Face Spaces
|
7 |
+
if os.name == 'posix': # Unix-like OS
|
8 |
+
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
9 |
|
10 |
st.set_page_config(page_title="Image to Text OCR", layout="centered")
|
11 |
|
|
|
20 |
|
21 |
if st.button("Extract Text"):
|
22 |
with st.spinner("Extracting text..."):
|
23 |
+
try:
|
24 |
+
text = pytesseract.image_to_string(image)
|
25 |
+
st.subheader("Extracted Text")
|
26 |
+
st.text_area("Text Output", value=text, height=300)
|
27 |
+
except pytesseract.pytesseract.TesseractNotFoundError:
|
28 |
+
st.error("Tesseract is not installed or not in the PATH. Please check your environment settings.")
|
29 |
else:
|
30 |
st.info("Please upload an image to get started.")
|
31 |
|
32 |
|
33 |
+
|