Exemplo n.º 1
0
    def test_storage_remembers_type(self):
        from model import TextModel, EquationModel, ImageModel, WrenModel
        text_model = TextModel('text1')
        text_model.save()
        equation_model = EquationModel('equation1')
        equation_model.save()
        image_model = ImageModel('image1')
        image_model.save()

        self.assertIsInstance(WrenModel.load(text_model.key),
                              TextModel)
        self.assertIsInstance(WrenModel.load(equation_model.key),
                              EquationModel)
        self.assertIsInstance(WrenModel.load(image_model.key),
                              ImageModel)
Exemplo n.º 2
0
def main(terminal_flag):
    """Main program."""
    # Create PyQt5 application
    app = QApplication(
        sys.argv
    )  # Note: There must be exactly one instance of QApplication active at a time
    app.setWindowIcon(QIcon('icons/ieviewer.png'))  # Set program icon

    # Create model, view and controller
    model = ImageModel(terminal_flag)
    view = View(model)
    controller = Controller(model, view)

    # Start main window
    main_window = controller.get_main_window()
    main_window.show()

    sys.exit(app.exec_())
Exemplo n.º 3
0
import base64
import json
from io import BytesIO

import cv2
import numpy as np
from flask import Flask, Response, render_template, request

from model import ImageModel

app = Flask(__name__)
model = ImageModel('sample_model')


def predict(data):
    image_dec = cv2.imdecode(data, 1).astype(np.float32) / 255.0
    x = np.expand_dims(image_dec, axis=0)
    label = model.predict(x)
    return label


@app.route('/predict_from_base64/', methods=['POST'])
def predict_from_base64():
    data_json = json.loads(request.data)
    image_bytes = base64.b64decode(data_json['image'])
    image_np = np.frombuffer(image_bytes, dtype='uint8')
    label = predict(image_np)
    return Response(json.dumps({'label': label}))


@app.route('/predict_from_image/', methods=['POST'])