rththr commited on
Commit
ec7bbba
·
verified ·
1 Parent(s): f1e60a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -27
app.py CHANGED
@@ -1,33 +1,30 @@
1
- import gradio as gr
2
- from paddleocr import PaddleOCR
3
- import cv2
4
- import numpy as np
5
 
6
- # Initialize OCR engine (loads models into memory once)
7
- # lang='en' supports English. Change to 'ch' for Chinese/English mix.
8
- ocr = PaddleOCR(use_angle_cls=True, lang='en', use_gpu=False)
9
 
10
- def run_ocr(image):
11
- if image is None:
12
- return "No image provided"
 
 
 
 
 
13
 
14
- # Gradio passes image as numpy array, perfect for PaddleOCR
15
- result = ocr.ocr(image, cls=True)
 
 
16
 
17
- txts = []
18
- if result and result[0]:
19
- # Extract just the text from the complex result
20
- txts = [line[1][0] for line in result[0]]
21
 
22
- return "\n".join(txts)
 
23
 
24
- # Create the interface
25
- # The 'api_name' is crucial - it's how your HTML file will find this function
26
- demo = gr.Interface(
27
- fn=run_ocr,
28
- inputs=gr.Image(type="numpy"),
29
- outputs="text",
30
- )
31
-
32
- if __name__ == "__main__":
33
- demo.launch()
 
1
+ # 1. Use Python 3.10 (Most stable for Paddle)
2
+ FROM python:3.10
 
 
3
 
4
+ # 2. Set working directory
5
+ WORKDIR /app
 
6
 
7
+ # 3. INSTALL MISSING GRAPHICS LIBRARIES (This fixes the "Starting" crash)
8
+ RUN apt-get update && apt-get install -y \
9
+ libgl1 \
10
+ libglib2.0-0 \
11
+ libsm6 \
12
+ libxext6 \
13
+ libxrender-dev \
14
+ && rm -rf /var/lib/apt/lists/*
15
 
16
+ # 4. Copy requirements and install
17
+ COPY requirements.txt requirements.txt
18
+ RUN pip install --no-cache-dir --upgrade pip && \
19
+ pip install --no-cache-dir -r requirements.txt
20
 
21
+ # 5. Pre-download the models so they don't timeout your browser
22
+ # (This runs a dummy scan during build to cache the files)
23
+ RUN pip install paddlepaddle==2.6.2 paddleocr==2.7.3 numpy<2.0.0
24
+ RUN python -c "from paddleocr import PaddleOCR; PaddleOCR(use_angle_cls=False, lang='en', use_gpu=False)"
25
 
26
+ # 6. Copy App Code
27
+ COPY . .
28
 
29
+ # 7. Start the Server
30
+ CMD ["python", "app.py"]