def homepage()

in src/edge/run.py [0:0]


def homepage():
    # Get a random image from the directory
    list_img_inf = glob.glob('./static/**/*.png')

    if len(list_img_inf) == 0:
        return render_template('main_noimg.html',
            loaded_models=models_loaded
        )

    inference_img_path = random.choice(list_img_inf)
    inference_img_filename = re.search(r'(?<=\/static\/).+$', inference_img_path)[0]

    # Run inferece on this image
    y_clf, t_ms_clf = run_classification_inference(edge_agent, inference_img_path)
    y_segm, t_ms_segm = run_segmentation_inference(edge_agent, inference_img_path)

    # Synthesize mask into binary image
    if y_segm is not None:
        segm_img_encoded = app.create_b64_img_from_mask(y_segm)
        segm_img_decoded_utf8 = segm_img_encoded.decode('utf-8')
        logging.info('Model latency: t_segm=%fms' %  t_ms_segm)
    else:
        segm_img_encoded = None
        segm_img_decoded_utf8 = None

    # Extract predictions from the y array
    # Assuming that the entry at index=0 is the probability for "normal" and the other for "anomalous"
    clf_class_labels = ['normal', 'anomalous']
    if y_clf is not None:
        y_clf_normal = np.round(y_clf[0], decimals=6)
        y_clf_anomalous = np.round(y_clf[1], decimals=6)
        y_clf_class = clf_class_labels[np.argmax(y_clf)]
        logging.info('Model latency: t_classification=%fms' % t_ms_clf)
    else:
        y_clf_normal = None
        y_clf_anomalous = None
        y_clf_class = None


    # Return rendered HTML page with predictions
    return render_template('main.html',
        loaded_models=models_loaded,
        image_file=inference_img_filename,
        y_clf_normal=y_clf_normal,
        y_clf_anomalous=y_clf_anomalous,
        y_clf_class=y_clf_class,
        y_segm_img=segm_img_decoded_utf8,
        latency_clf=t_ms_clf,
        latency_segm=t_ms_segm
    )