|
|
from flask import Flask, request, render_template |
|
|
import pytesseract |
|
|
from PIL import Image |
|
|
import os |
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
|
UPLOAD_FOLDER = 'uploads' |
|
|
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER |
|
|
|
|
|
|
|
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True) |
|
|
|
|
|
|
|
|
@app.route('/') |
|
|
def index(): |
|
|
return render_template('index.html') |
|
|
|
|
|
|
|
|
@app.route('/upload', methods=['POST']) |
|
|
def upload_file(): |
|
|
if 'invoice_image' not in request.files: |
|
|
return 'No file part' |
|
|
file = request.files['invoice_image'] |
|
|
if file.filename == '': |
|
|
return 'No selected file' |
|
|
if file: |
|
|
file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) |
|
|
file.save(file_path) |
|
|
|
|
|
|
|
|
img = Image.open(file_path) |
|
|
extracted_text = pytesseract.image_to_string(img) |
|
|
|
|
|
|
|
|
return render_template('index.html', extracted_text=extracted_text) |
|
|
|
|
|
if __name__ == '__main__': |
|
|
app.run(debug=True) |
|
|
|