Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +21 -0
- app.py +26 -0
- requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9-slim
|
2 |
+
|
3 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
4 |
+
|
5 |
+
# Install tesseract and dependencies
|
6 |
+
RUN apt-get update && apt-get install -y \
|
7 |
+
tesseract-ocr \
|
8 |
+
libtesseract-dev \
|
9 |
+
libleptonica-dev \
|
10 |
+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
11 |
+
|
12 |
+
# Set work directory
|
13 |
+
WORKDIR /app
|
14 |
+
|
15 |
+
# Copy files
|
16 |
+
COPY requirements.txt .
|
17 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
18 |
+
COPY app.py .
|
19 |
+
|
20 |
+
EXPOSE 7860
|
21 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import pytesseract
|
4 |
+
|
5 |
+
st.set_page_config(page_title="OCR - Image to Text", layout="centered")
|
6 |
+
st.title("🖼️ OCR - Image to Text")
|
7 |
+
|
8 |
+
st.write("Upload an image to extract text:")
|
9 |
+
|
10 |
+
# Upload block
|
11 |
+
uploaded_file = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg"])
|
12 |
+
|
13 |
+
# Show uploaded image and extraction options
|
14 |
+
if uploaded_file is not None:
|
15 |
+
try:
|
16 |
+
image = Image.open(uploaded_file)
|
17 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
18 |
+
|
19 |
+
if st.button("Extract Text"):
|
20 |
+
with st.spinner("Extracting text..."):
|
21 |
+
text = pytesseract.image_to_string(image)
|
22 |
+
st.success("✅ Text extracted!")
|
23 |
+
st.text_area("Extracted Text", value=text, height=300)
|
24 |
+
|
25 |
+
except Exception as e:
|
26 |
+
st.error(f"❌ Error: {e}")
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pytesseract
|
3 |
+
pillow
|