Beispiel #1
0
def predict():
    if model:
        try:
            input_df = pd.DataFrame(request.json)
            predictions = model_utils.predict(input_df, model)
            return jsonify(predictions)
        except Exception as e:
            return jsonify({'error': str(e), 'trace': traceback.format_exc()})
    else:
        print('You need to train a model before you can make predictions.')
        return 'error: no model'
Beispiel #2
0
def predict():
    print(model)
    if model:
        try:
            input_df = pd.DataFrame(request.json)
            predictions = model_utils.predict(input_df, model, model_columns)
            return jsonify(predictions)
        except Exception as e:
            return jsonify({'error': str(e), 'trace': traceback.format_exc()})
    else:
        return jsonify({'error': 'Please train model before trying to predict'})
Beispiel #3
0
def predict():
    print("Data is\n", request.json)
    input_df=model_utils.transform(request.json)
    print("Data transformed\n",input_df)

    if model:
        print("model exists")
        try:
            #input_df = pd.DataFrame(request.json)
            predictions = model_utils.predict(input_df, model)
            #print("Predictions", predictions)
            return jsonify(predictions)
        except Exception as e:
            return jsonify({'error': str(e), 'trace': traceback.format_exc()})
    else:
        print('You need to train a model before you can make predictions.')
        return 'error: no model'
Beispiel #4
0

@st.cache
def model_loader(config):
    model = load_model(config["paths"]["model_path"])
    return model


model = model_loader(config)

st.write("""
# Multi task classifier
## Enter the image url
""")
url = st.text_input("Enter image url")
if url:
    current_image = download_image(url)
    predictions = predict(model, current_image, config)
    col1, col2 = st.beta_columns(2)
    col1.write("Original image")
    col1.image(current_image, use_column_width=True)
    for encoder in predictions.keys():
        current_dict = predictions[encoder]
        current_df = pd.DataFrame(
            index=current_dict.keys(),
            data=current_dict.values(),
            columns=["prediction"],
        ).sort_values(by="prediction", ascending=False)
        col2.write(f"{encoder} prediction")
        col2.dataframe(current_df)