Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,31 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import pytesseract
|
|
|
4 |
|
5 |
-
st.set_page_config(page_title="OCR
|
6 |
st.title("🖼️ OCR - Image to Text")
|
7 |
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
if st.button("Extract Text"):
|
15 |
-
with st.spinner("Extracting..."):
|
16 |
-
text = pytesseract.image_to_string(image)
|
17 |
-
st.subheader("Extracted Text")
|
18 |
-
st.text_area("Result", text, height=300)
|
19 |
|
20 |
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import pytesseract
|
4 |
+
import io
|
5 |
|
6 |
+
st.set_page_config(page_title="OCR - Image to Text", layout="centered")
|
7 |
st.title("🖼️ OCR - Image to Text")
|
8 |
|
9 |
+
st.write("Upload an image to extract text:")
|
10 |
|
11 |
+
uploaded_file = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg"])
|
12 |
+
|
13 |
+
if uploaded_file is not None:
|
14 |
+
try:
|
15 |
+
# Convert uploaded image to bytes and open with PIL
|
16 |
+
image = Image.open(uploaded_file)
|
17 |
+
|
18 |
+
# Show image preview
|
19 |
+
st.image(image, caption="Preview", use_column_width=True)
|
20 |
+
|
21 |
+
if st.button("Extract Text"):
|
22 |
+
with st.spinner("Extracting text..."):
|
23 |
+
text = pytesseract.image_to_string(image)
|
24 |
+
st.success("Text extracted successfully!")
|
25 |
+
st.text_area("Extracted Text", text, height=300)
|
26 |
+
|
27 |
+
except Exception as e:
|
28 |
+
st.error(f"⚠️ Failed to process the image: {e}")
|
29 |
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
|