diff --git a/dbmanager.py b/dbmanager.py new file mode 100644 index 0000000..234685b --- /dev/null +++ b/dbmanager.py @@ -0,0 +1 @@ +from flask_sqlalchemy import SQLAlchemy diff --git a/server.py b/server.py index e69de29..eb87231 100644 --- a/server.py +++ b/server.py @@ -0,0 +1,59 @@ +from flask import Flask, request, jsonify +import os +from pyplatex import ANPR +import torch +from ultralytics.nn.tasks import DetectionModel +import asyncio + +torch.serialization.add_safe_globals({"DetectionModel": DetectionModel}) + +# Web Server +app = Flask(__name__) + +# Saving images locally +UPLOAD_FOLDER = "uploads" +os.makedirs(UPLOAD_FOLDER, exist_ok=True) + + +# Default app route +@app.route("/") +def home(): + return "Hello, World!" + + +# API to process vehicle +@app.route("/api", methods=["POST"]) +def data(): + # Check if image is present + if "image" not in request.files: + return jsonify({"error": "No file part"}), 400 + + file = request.files["image"] # get the image from the packet + + if file.filename == "" or not file.filename: + return jsonify({"error": "No selected file"}), 400 + + # Check if image ends in .jpg + if file.filename.lower().endswith(".jpg"): + filepath = os.path.join(UPLOAD_FOLDER, file.filename) + file.save(filepath) + print(asyncio.run(process_image(filepath))) + return jsonify( + { + "message": "File uploaded successfully", + "filename": file.filename, + "status": True, + } + ) + + return jsonify({"error": "Only JPEG files allowed"}), 400 + + +async def process_image(file: str): + anpr = ANPR() + plates = await anpr.detect(file) + return plates + + +if __name__ == "__main__": + app.run(host="192.168.137.1", port=2222, debug=True) diff --git a/uploads/image.jpg b/uploads/image.jpg new file mode 100644 index 0000000..80f57d6 Binary files /dev/null and b/uploads/image.jpg differ