baxin commited on
Commit
4aa5de4
Β·
1 Parent(s): 7aea3f2

initial commit πŸ€–πŸ€–πŸ€–

Browse files
Files changed (3) hide show
  1. Dockerfile +26 -0
  2. app.py +30 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.10-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y \
9
+ tesseract-ocr \
10
+ libtesseract-dev \
11
+ libgl1-mesa-glx \
12
+ libglib2.0-0 \
13
+ && apt-get clean \
14
+ && rm -rf /var/lib/apt/lists/*
15
+
16
+ # Copy the current directory contents into the container at /app
17
+ COPY . /app
18
+
19
+ # Install any needed packages specified in requirements.txt
20
+ RUN pip install --no-cache-dir -r requirements.txt
21
+
22
+ # Make port 7860 available to the world outside this container
23
+ EXPOSE 7860
24
+
25
+ # Run app.py when the container launches
26
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pytesseract
3
+ from PIL import Image
4
+ import os
5
+
6
+ def extract_text(image_path):
7
+ if not image_path:
8
+ return "No image uploaded. Please upload an image."
9
+
10
+ if not os.path.exists(image_path):
11
+ return f"Error: File not found at {image_path}"
12
+
13
+ try:
14
+ img = Image.open(image_path)
15
+ text = pytesseract.image_to_string(img)
16
+ return text if text.strip() else "No text detected in the image."
17
+ except Exception as e:
18
+ return f"An error occurred: {str(e)}"
19
+
20
+ # Create the Gradio interface (same as before)
21
+ iface = gr.Interface(
22
+ fn=extract_text,
23
+ inputs=gr.Image(type="filepath", label="Upload an image"),
24
+ outputs=gr.Textbox(label="Extracted Text"),
25
+ title="Image Text Extractor",
26
+ description="Upload an image and extract text from it using OCR."
27
+ )
28
+
29
+ # Launch the interface
30
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ pytesseract
3
+ Pillow