KZTech commited on
Commit
613d9e4
·
verified ·
1 Parent(s): 0a04b37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import streamlit as st
2
  from PIL import Image
3
  import pytesseract
 
4
 
5
- # Explicitly set the Tesseract command path
6
- pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
 
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
- text = pytesseract.image_to_string(image)
22
- st.subheader("Extracted Text")
23
- st.text_area("Text Output", value=text, height=300)
 
 
 
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
+