from flask import Flask, redirect, rendertemplate, request, jsonify, sendfromdirectory,…
- User
from flask import Flask, redirect, render_template, request, jsonify, send_from_directory, url_for from custom_ocr_model import CustomOCRModel import os
app = Flask(name)
Load the OCR models for HDDT.GOV and THUECANHAN
hddt_gov = CustomOCRModel(img_width=200, img_height=40, max_length=6, characters=[ '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z'], model_name='ocr_model_v2.h5')
thue_ca_nhan = model = CustomOCRModel(img_width=68, img_height=22, max_length=4, characters=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'], model_name='ocr_model_v4_thuecanhan.h5')
@app.route('/health-check', methods=['GET']) def health_check(): return jsonify({"status": "healthy"})
@app.route('/') def index(): return render_template('captcha.html')
@app.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')
@app.route('/predict', methods=['POST']) def predict(): try: # Get the image from the request img = request.files['image'].read()
# Get the 'vendor' parameter from the query string vendor = request.args.get('vendor', default='', type=str) pred_text = '' model = None if vendor == 'hddtgov': model = hddt_gov elif vendor == 'thuecanhan': model = thue_ca_nhan else: raise Exception('Invalid vendor') pred_text = model.predict_image(img) # Return the prediction as JSON return jsonify({"captcha-text": pred_text[0]}) except Exception as e: return jsonify({"error": str(e)})if name == 'main': app.run() giúp tôi convert svg dạng text sang jpg hoặc png sau đó mới đưa vào model
- Assistant
- User
trường hợp nếu có image thì để nguyên chứ
- Assistant
- User
giúp tôi dựng pipeliene yaml azure devops để build tự động đoạn code trên
- Assistant
- User
project của tôi có # Gunicorn configuration file import multiprocessing
max_requests = 1000 max_requests_jitter = 50
log_file = "-"
bind = "0.0.0.0:50505"
workers = (multiprocessing.cpu_count() * 2) + 1 threads = workers
timeout = 120 # syntax=docker/dockerfile:1
FROM python:3.11
WORKDIR /code
COPY requirements.txt .
RUN pip3 install -r requirements.txt
COPY . .
EXPOSE 50505
ENTRYPOINT ["gunicorn", "app:app"]
- Assistant