Ejemplo n.º 1
0
async def _predict(payload: PredictPayload):
    if payload.experiment_id == 'latest':
        payload.experiment_id = max(os.listdir(config.EXPERIMENTS_DIR))
    prediction = predict.predict(experiment_id=payload.experiment_id,
                                 text=payload.text)
    response = {
        'message': HTTPStatus.OK.phrase,
        'status-code': HTTPStatus.OK,
        'data': {
            "prediction": prediction
        }
    }
    config.logger.info(json.dumps(response, indent=2))
    return response
Ejemplo n.º 2
0
model, word_map = predict.get_run_components(run_dir=best_run_dir)

# Pages
page = st.sidebar.selectbox(
    "Choose a page", ['Prediction', 'Model details'])

if page == 'Prediction':

    st.header("ЁЯЪА Try it out!")

    # Input text
    text = st.text_input(
        "Enter text to classify", value="The Canadian government officials proposed the new federal law.")

    # Predict
    results = predict.predict(inputs=[{'text': text}], model=model, word_map=word_map)

    # Results
    raw_text = results[0]['raw_input']
    st.write("**Raw text**:", raw_text)
    preprocessed_text = results[0]['preprocessed_input']
    st.write("**Preprocessed text**:", preprocessed_text)
    st.write("**Probabilities**:")
    st.json(results[0]['probabilities'])

    # Interpretability
    st.write("**Top n-grams**:")
    words = preprocessed_text.split(' ')
    top_n_grams = {}
    token_index_to_freq = {i: 0 for i in range(len(words))}
Ejemplo n.º 3
0
def predict_fn(input_data, model):
    prediction = predict.predict(
        experiment_id='latest', inputs=input_data)
    return prediction