Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,29 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import pytesseract
|
4 |
-
import os
|
5 |
import io
|
6 |
|
7 |
-
#
|
8 |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
9 |
|
10 |
st.set_page_config(page_title="OCR – Image to Text", layout="centered")
|
11 |
st.title("🖼️ OCR – Image to Text")
|
12 |
-
st.write("Upload a PNG, JPG or JPEG image to extract text.")
|
13 |
|
14 |
-
|
15 |
|
|
|
16 |
if uploaded_file:
|
17 |
try:
|
18 |
-
# Read and display image
|
19 |
image = Image.open(io.BytesIO(uploaded_file.read()))
|
20 |
-
st.image(image, caption="
|
21 |
|
22 |
-
# Extract text on button click
|
23 |
if st.button("Extract Text"):
|
24 |
-
with st.spinner("
|
25 |
extracted_text = pytesseract.image_to_string(image)
|
26 |
-
st.
|
27 |
-
st.text_area(
|
28 |
-
except Exception as e:
|
29 |
-
st.error(f"Failed to process image: {e}")
|
30 |
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import pytesseract
|
|
|
4 |
import io
|
5 |
|
6 |
+
# Set Tesseract binary path for Hugging Face
|
7 |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
8 |
|
9 |
st.set_page_config(page_title="OCR – Image to Text", layout="centered")
|
10 |
st.title("🖼️ OCR – Image to Text")
|
|
|
11 |
|
12 |
+
st.write("Upload an image to extract text using Tesseract OCR.")
|
13 |
|
14 |
+
uploaded_file = st.file_uploader("Choose an image", type=["png", "jpg", "jpeg"])
|
15 |
if uploaded_file:
|
16 |
try:
|
|
|
17 |
image = Image.open(io.BytesIO(uploaded_file.read()))
|
18 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
19 |
|
|
|
20 |
if st.button("Extract Text"):
|
21 |
+
with st.spinner("Extracting text..."):
|
22 |
extracted_text = pytesseract.image_to_string(image)
|
23 |
+
st.success("Text extracted!")
|
24 |
+
st.text_area("Extracted Text", extracted_text, height=300)
|
|
|
|
|
25 |
|
26 |
+
except Exception as e:
|
27 |
+
st.error(f"❌ Failed to process image: {e}")
|
28 |
+
else:
|
29 |
+
st.info("Please upload an image.")
|