feat(ocr): make OCR functionality optional via configuration
The OCR feature can now be enabled or disabled using a new `OCR_ENABLED` configuration flag. This allows for more flexible deployments where the OCR feature is not required, reducing the application's resource footprint and dependency overhead. The backend now conditionally initializes the OCR engine and its associated route. The frontend UI for OCR uploads is also rendered conditionally based on this setting.
This commit is contained in:
parent
5a5692d8cc
commit
bcab963b99
5
app.py
5
app.py
@ -26,6 +26,7 @@ else:
|
||||
app.config.from_object(DevelopmentConfig)
|
||||
cache = Cache(app, config={"CACHE_TYPE": "SimpleCache"})
|
||||
|
||||
if app.config.get("OCR_ENABLED"):
|
||||
ocr = PaddleOCR(use_angle_cls=True, lang='en') # Adjust language if needed
|
||||
|
||||
app.config["SESSION_COOKIE_SECURE"] = not app.config["DEBUG"]
|
||||
@ -85,6 +86,7 @@ def home():
|
||||
accounts=count,
|
||||
current_month_accounts=current_month_accounts,
|
||||
expired_accounts=expired_accounts,
|
||||
ocr_enabled=app.config.get("OCR_ENABLED"),
|
||||
)
|
||||
return render_template("index.html")
|
||||
|
||||
@ -163,7 +165,7 @@ def add_account():
|
||||
return redirect(url_for("user_accounts"))
|
||||
return render_template("add_account.html")
|
||||
|
||||
return render_template("add_account.html")
|
||||
return render_template("add_account.html", ocr_enabled=app.config.get("OCR_ENABLED"))
|
||||
|
||||
|
||||
@app.route("/accounts/delete", methods=["POST"])
|
||||
@ -187,6 +189,7 @@ def stream_names():
|
||||
return jsonify(stream_names)
|
||||
|
||||
|
||||
if app.config.get("OCR_ENABLED"):
|
||||
@app.route('/OCRupload', methods=['POST'])
|
||||
def OCRupload():
|
||||
if 'image' not in request.files:
|
||||
|
@ -74,6 +74,7 @@
|
||||
<span id="buttonText">Add Account</span>
|
||||
</button>
|
||||
</form>
|
||||
{% if ocr_enabled %}
|
||||
<hr>
|
||||
<h2>Load Details Via OCR</h2>
|
||||
<form action="/OCRupload" method="POST" enctype="multipart/form-data" onsubmit="showLoadingOCR()">
|
||||
@ -86,6 +87,7 @@
|
||||
<span id="ocrButtonText">Load Details</span>
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
</main>
|
||||
<footer class="bg-dark text-white text-center py-3 mt-5">
|
||||
|
Loading…
x
Reference in New Issue
Block a user