import gradio as gr import generate_annotated_diffs df = generate_annotated_diffs.data_with_annotated_diffs() n_diffs = len(df) def update_view(diff_idx): diff_idx -= 1 return df.iloc[diff_idx]['annotated_diff'], df.iloc[diff_idx]['commit_msg_start'], df.iloc[diff_idx][ 'commit_msg_end'], df.iloc[diff_idx][ 'session'], f"https://github.com/{df.iloc[diff_idx]['repo']}/commit/{df.iloc[diff_idx]['hash']}" if __name__ == '__main__': with gr.Blocks(theme=gr.themes.Soft()) as application: slider = gr.Slider(minimum=1, maximum=n_diffs, step=1, value=1, label=f"Sample number (total: {n_diffs})") diff_view = gr.Highlightedtext(combine_adjacent=True, color_map={'+': "green", '-': "red"}) start_view = gr.Textbox(interactive=False, label="Start message", container=True) end_view = gr.Textbox(interactive=False, label="End message", container=True) session_view = gr.Textbox(interactive=False, label="Session", container=True) link_view = gr.Markdown() slider.change(update_view, inputs=slider, outputs=[diff_view, start_view, end_view, session_view, link_view]) application.load(update_view, inputs=slider, outputs=[diff_view, start_view, end_view, session_view, link_view]) application.launch()