import os import gradio as gr from git import InvalidGitRepositoryError from git_graph import render_branch_graph DEFAULT_REPO_PATH = os.environ.get("REPO_PATH", os.getcwd()) def draw_graph(repo_path: str, next_commit_message: str): repo_path = repo_path.strip() or DEFAULT_REPO_PATH try: return render_branch_graph(repo_path, next_commit_message) except InvalidGitRepositoryError: raise gr.Error(f"'{repo_path}' is not a git repository.") with gr.Blocks(title="Git Branch Visualizer", theme=gr.themes.Base()) as demo: gr.Markdown("## Git Branch Graph Visualizer") gr.Markdown( "Shows all local **and remote** branches as a commit DAG. " "Type a commit message to preview **where the next commit lands** (gold ghost node)." ) with gr.Row(): repo_path_input = gr.Textbox( label="Repository path", value=DEFAULT_REPO_PATH, placeholder="/path/to/your/repo", scale=3, ) next_commit_input = gr.Textbox( label="Next commit message (preview)", placeholder="feat: add new feature", scale=2, ) render_button = gr.Button("Render Graph", variant="primary") graph_output = gr.Plot(label="Branch Graph") info_output = gr.Markdown() render_button.click( fn=draw_graph, inputs=[repo_path_input, next_commit_input], outputs=[graph_output, info_output], ) demo.load( fn=draw_graph, inputs=[repo_path_input, next_commit_input], outputs=[graph_output, info_output], ) if __name__ == "__main__": demo.launch()