import gradio as gr from datetime import datetime weights = [] def add_weight(weight, all_weights, total_weight): weights.append(int(weight)) callback.flag([all_weights, total_weight]) return weights, sum(weights) def reset_weights(): weights.clear() return weights, 0 callback = gr.CSVLogger() with gr.Blocks(theme=gr.themes.Soft()) as iface: gr.Markdown("# Weigh Grapes") with gr.Row(): with gr.Column(): weight = gr.Number(label = "Crate Weight") add = gr.Button("Submit Weight") with gr.Column(): all_weights = gr.Text(label = "All Weights", hidden = True) total_weight = gr.Text(label = "Total Weight") with gr.Row(): reset = gr.Button("Reset Total") tolog = [all_weights, total_weight] callback.setup(tolog, "flagged_data_points") add.click(add_weight, inputs = [weight] + tolog, outputs = [all_weights, total_weight]) reset.click(reset_weights, inputs = [], outputs = [all_weights, total_weight]) # Launch the Gradio interface iface.launch()