Exemplo n.º 1
0
def ajax_detector():
    if request.method == 'POST':
        url = request.json
        result = get_prediction(url['url'])
        title = result[0]
        prediction = result[1]
        result = {'title': title, 'tag': prediction}
        return jsonify(result)
Exemplo n.º 2
0
def predict():

    if request.method == 'POST':
        # we will get the file from the request
        file = request.files['file']
        # convert that to bytes
        img_bytes = file.read()
        class_id, class_name = predictor.get_prediction(image_bytes=img_bytes)
        return jsonify({'class_id': class_id, 'class_name': class_name})
Exemplo n.º 3
0
    def get(self, request):
        #data_dir = '/Users/lconroy/comp_msc/dublink_bus/final_models'
        #data_dir = 'C:\\Users\\rbyrn\\Desktop\\dublinbus\\app\\model_integration'
        data_dir = os.path.join(settings.BASE_DIR, 'backend_data_store', 'final_models')

        lineid = request.query_params.get('lineid').upper()
        routeid = request.query_params.get('routeid')
        start_stop = request.query_params.get('start_stop')
        end_stop = request.query_params.get('end_stop')
        time_secs = request.query_params.get('time_secs')
        dow = request.query_params.get('dow')
        rain = request.query_params.get('rain')
        temp = request.query_params.get('temp')
        clouds = request.query_params.get('clouds')
        feels_like = request.query_params.get('feels_like')
        main = request.query_params.get('main')

        try:
            model_pickle = os.path.join(data_dir, 'pickle_file_XG_03082020', 'XG_{}.pkl'.format(lineid))
            #model_pickle = os.path.join(data_dir, 'pickle_file\\XG_{}.pkl'.format(lineid))
            model = joblib.load(open(model_pickle, 'rb'))
        except Exception as e:
            print(e)
            return Response("ERROR: incorrect file structure", status=status.HTTP_500_INTERNAL_SERVER_ERROR)
        #direction = 0
        #with open(os.path.join(data_dir,'stop_sequence/stop_{0}.csv'.format(lineid)), 'r') as f:
         #   for line in f:
          #      if line.split(",")[1] == routeid:
           #         direction = line.split(",")[2]
            #        break
        #if direction == 0:
         #   return Response("ERROR: cannot get direction", status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        m_args = {
            'lineid': lineid,
            'start_stop': start_stop,
            'end_stop': end_stop,
            'time_secs': time_secs,
            'dow': dow,
            'holiday': "0",
            'temp': temp,
            'feels_like': feels_like,
            'clouds_all': clouds,
            'weather_main': main
        }

        data = {}
        data["journey_info"] = get_prediction(model, m_args, data_dir)

        if "error" in data["journey_info"].keys():
            if data["journey_info"]["error"] == "file structure error":
                return Response("ERROR IN FILE STRUCTURE", status=status.HTTP_500_INTERNAL_SERVER_ERROR)
            return Response("ERROR IN MODEL", status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        return Response(data, status=status.HTTP_200_OK)
def hello_world():
    if request.method == "GET":
        return render_template("index.html")

    if request.method == "POST":
        if "file" not in request.files:
            return "file not uploaded !!!"

        file = request.files["file"]
        image = file.read()
        flower = get_prediction(image_bytes=image)
        return render_template("result.html", value=flower)
Exemplo n.º 5
0
def get_image():
    if request.method == 'POST':
        f = request.files['file']
        sfname = os.path.join('static/images/', str(secure_filename(f.filename)).lower())
        f.save(sfname)
        image = load_and_preprocess_image(sfname, path='')
        predictions = get_prediction(image, model)
        prediction_str = "This cat most likely is a {} with a {:.2f}" \
                         " percent confidence.".format(predictions[0][np.argmax(predictions[1])],
                                                       100 * np.max(predictions[1]))

        return render_template('prediction.html', pred_data=zip(*predictions), prediction=prediction_str,
                               image='../' + sfname)
Exemplo n.º 6
0
    def stream(self):
        while True:
            ret, frame = self.cap.read()
            if not ret: # EOF
                break
            frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
            # flip the image horizontally
            frame = cv2.flip(frame, 1)

            bounding = mpHelper.getBounding(frame)

    # No crop with box
            cv2.imshow(str(id(self)), bounding[0])
            
    # Crop
            crops = bounding[1]
            if (crops and len(crops) > 0):
                # cv2.imshow(str(id(self)), crops[0])
                print(get_prediction(crops[0]))

            c = cv2.waitKey(1)
            if c == 27: #ESC key
                break
Exemplo n.º 7
0
def make_prediction():
    prices = request.get_json()
    update_data(prices)
    predictions = get_prediction(prices, DATA)
    return jsonify(render_template('predictions.html', predictions=predictions))
Exemplo n.º 8
0
def get_pred():
    return get_prediction(request.args.to_dict())
Exemplo n.º 9
0
def labeled_demo(bot, update):
    prediction = get_prediction(labeled=True)
    bot.sendPhoto(chat_id=update.message.chat_id,
                  photo=prediction['picture'],
                  caption=prediction['message'])