import subprocess import gradio as gr # Paths BINARY_PATH = "./bin/llama-cli" # prebuilt binary from zip MODEL_PATH = "./qwen0.5-finetuned.gguf" # Commit message prompt template commit_prompt = """Generate a meaningful commit message explaining all the changes in the provided Git diff. ### Git Diff: {} ### Commit Message: """ # Example git diff prefilled in Gradio git_diff_example = """ diff --git a/index.html b/index.html index 89abcde..f123456 100644 --- a/index.html +++ b/index.html @@ -5,16 +5,6 @@

Welcome to My Page

- - - - - - - - - -
NameAge
John Doe30
+

This is a newly added paragraph replacing the table.

""" def generate_commit(git_diff: str, max_tokens: int = 64) -> str: """Generate a commit message using the llama-cli binary.""" if not git_diff.strip(): return "Please provide a git diff to summarize." prompt_text = commit_prompt.format(git_diff) cmd = [ BINARY_PATH, "-m", MODEL_PATH, "-p", prompt_text, "-n", str(max_tokens) ] try: # Run the binary and capture output result = subprocess.run(cmd, capture_output=True, text=True, check=True) return result.stdout.strip() except subprocess.CalledProcessError as e: return f"Error running binary: {e}\n{e.stderr}" if __name__ == "__main__": demo = gr.Interface( fn=generate_commit, inputs=[ gr.Textbox(lines=30, label="Git Diff", value=git_diff_example), gr.Slider(1, 2048, value=64, step=1, label="max_tokens") ], outputs=gr.Textbox(label="Commit Message", lines=8), title="Commit Message Generator", description="Paste a git diff and generate a concise commit message using the GGUF model via llama-cli binary.", allow_flagging="never" ) demo.launch(share=False)