Basic server for demo, database manager wip

This commit is contained in:
2025-04-10 17:04:04 +02:00
parent a11e2cb59f
commit 02979e2cee
3 changed files with 60 additions and 0 deletions

1
dbmanager.py Normal file
View File

@@ -0,0 +1 @@
from flask_sqlalchemy import SQLAlchemy

View File

@@ -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)

BIN
uploads/image.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB