diff --git a/app.py b/app.py index 3674424..14d0786 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ # app.py -from flask import Flask, render_template, request, redirect, url_for, session, flash, send_file +from flask import Flask, render_template, request, redirect, url_for, session, send_file, jsonify from flask_caching import Cache import requests.auth import os @@ -10,6 +10,10 @@ import requests import base64 from flask import Flask from config import DevelopmentConfig +from paddleocr import PaddleOCR +from PIL import Image +import numpy as np + app = Flask(__name__) app.config.from_object( @@ -17,6 +21,8 @@ app.config.from_object( ) cache = Cache(app, config={"CACHE_TYPE": "SimpleCache"}) +ocr = PaddleOCR(use_angle_cls=True, lang='en') # Adjust language if needed + app.config['SESSION_COOKIE_SECURE'] = True # Only send cookie over HTTPS app.config['SESSION_COOKIE_HTTPONLY'] = True # Prevent JavaScript access app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' # Adjust for cross-site requests @@ -156,5 +162,23 @@ def delete_account(): return redirect(url_for("user_accounts")) +@app.route('/OCRupload', methods=['POST']) +def OCRupload(): + if 'image' not in request.files: + return jsonify({"error": "No image file found"}), 400 + # Get the uploaded file + file = request.files['image'] + try: + image = Image.open(file.stream) + image_np = np.array(image) + result = ocr.ocr(image_np) + # Extract text + extracted_text = [] + for line in result[0]: + extracted_text.append(line[1][0]) + return render_template("add_account.html", username=extracted_text[2], password=extracted_text[3]) + except Exception as e: + return jsonify({"error": str(e)}), 500 + if __name__ == "__main__": app.run(debug=app.config["DEBUG"], host=app.config["HOST"], port=app.config["PORT"]) diff --git a/requirements.txt b/requirements.txt index abb2183..ec69c21 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/templates/add_account.html b/templates/add_account.html index 271f27f..076cbce 100644 --- a/templates/add_account.html +++ b/templates/add_account.html @@ -6,16 +6,16 @@