Spaces:
Running
Running
File size: 1,263 Bytes
0bd0f00 93c87da 0bd0f00 93c87da 0bd0f00 93c87da 0bd0f00 93c87da 0bd0f00 93c87da 0bd0f00 93c87da 0bd0f00 93c87da 0bd0f00 93c87da 0bd0f00 93c87da 0bd0f00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
from flask import Flask, render_template, request
from paddleocr import PaddleOCR
import os
app = Flask(__name__)
# Create uploads directory if it doesn't exist
UPLOAD_FOLDER = 'uploads'
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
ocr = PaddleOCR(lang='en')
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
return render_template('index.html', error='No file selected')
file = request.files['file']
if file.filename == '':
return render_template('index.html', error='No file selected')
if file:
# Save the file to uploads directory
img_path = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(img_path)
# Perform OCR
result = ocr.ocr(img_path)
# Extract text from OCR result
text = ""
for line in result[0]:
text += line[1][0] + "\n"
return render_template('index.html', text=text, filename=file.filename)
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000) |