Spaces:
Sleeping
Sleeping
Commit
·
986b927
1
Parent(s):
4bc7466
newappy
Browse files
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
-
# app.py
|
| 2 |
from flask import Flask, render_template, request, redirect, flash, url_for
|
| 3 |
import os
|
| 4 |
-
from paddleocr import PaddleOCR
|
| 5 |
from werkzeug.utils import secure_filename
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
|
@@ -12,28 +10,16 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
|
| 12 |
# Ensure upload directory exists
|
| 13 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 14 |
|
| 15 |
-
# Initialize PaddleOCR once (CPU mode, English; angle_cls=False speeds up simple text)
|
| 16 |
-
import os
|
| 17 |
-
from paddleocr import PaddleOCR
|
| 18 |
-
|
| 19 |
-
# create /tmp/ocr_models directory if it doesn't exist
|
| 20 |
-
os.makedirs('/tmp/ocr_models', exist_ok=True)
|
| 21 |
-
|
| 22 |
-
ocr = PaddleOCR(
|
| 23 |
-
use_angle_cls=False,
|
| 24 |
-
use_gpu=False,
|
| 25 |
-
lang='en',
|
| 26 |
-
det_model_dir='/tmp/ocr_models/det',
|
| 27 |
-
rec_model_dir='/tmp/ocr_models/rec',
|
| 28 |
-
cls_model_dir='/tmp/ocr_models/cls'
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
@app.route('/', methods=['GET', 'POST'])
|
| 32 |
def index():
|
| 33 |
extracted_text = None
|
| 34 |
image_file = None
|
| 35 |
|
| 36 |
if request.method == 'POST':
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Check file in request
|
| 38 |
if 'image' not in request.files:
|
| 39 |
flash('No file part in the request.')
|
|
@@ -59,5 +45,6 @@ def index():
|
|
| 59 |
image_file = filename
|
| 60 |
|
| 61 |
return render_template('index.html', extracted_text=extracted_text, image_file=image_file)
|
|
|
|
| 62 |
if __name__ == '__main__':
|
| 63 |
-
app.run(
|
|
|
|
|
|
|
| 1 |
from flask import Flask, render_template, request, redirect, flash, url_for
|
| 2 |
import os
|
|
|
|
| 3 |
from werkzeug.utils import secure_filename
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
|
|
|
| 10 |
# Ensure upload directory exists
|
| 11 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
@app.route('/', methods=['GET', 'POST'])
|
| 14 |
def index():
|
| 15 |
extracted_text = None
|
| 16 |
image_file = None
|
| 17 |
|
| 18 |
if request.method == 'POST':
|
| 19 |
+
# Initialize PaddleOCR inside the route (avoids memory use at app startup)
|
| 20 |
+
from paddleocr import PaddleOCR
|
| 21 |
+
ocr = PaddleOCR(use_angle_cls=False, use_gpu=False, lang='en')
|
| 22 |
+
|
| 23 |
# Check file in request
|
| 24 |
if 'image' not in request.files:
|
| 25 |
flash('No file part in the request.')
|
|
|
|
| 45 |
image_file = filename
|
| 46 |
|
| 47 |
return render_template('index.html', extracted_text=extracted_text, image_file=image_file)
|
| 48 |
+
|
| 49 |
if __name__ == '__main__':
|
| 50 |
+
app.run(debug=True)
|