import gradio as gr from detection_pipeline import DetectionModel if gr.NO_RELOAD: model = DetectionModel() preds = [] def predict(image, threshold): global preds preds = model(image) return filter_preds(image, threshold) def filter_preds(image, threshold): preds_ = list(filter(lambda x: x[4] > threshold/100, preds)) output = model.visualize(image, preds_) return output with gr.Blocks() as interface: with gr.Row(): with gr.Column(): image = gr.Image(label="Input", value="sample/1.jpg") with gr.Column(): output = gr.Image(label="Output") with gr.Row(): with gr.Column(): threshold = gr.Slider(0, 100, 30, step=5, label="Threshold") threshold.release(filter_preds, inputs=[image, threshold], outputs=output) with gr.Column(): button = gr.Button(value="Detect") button.click(predict, [image, threshold], output) if __name__ == "__main__": interface.launch()