|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
classifier = pipeline( |
|
task="text-classification", |
|
model="CIRCL/cwe-parent-vulnerability-classification-roberta-base", |
|
return_all_scores=True |
|
) |
|
|
|
def predict_cwe(commit_message: str): |
|
""" |
|
Predict CWE(s) from a commit message using the model. |
|
""" |
|
results = classifier(commit_message)[0] |
|
|
|
sorted_results = sorted(results, key=lambda x: x["score"], reverse=True) |
|
|
|
return {item["label"]: round(float(item["score"]), 4) for item in sorted_results[:5]} |
|
|
|
|
|
demo = gr.Interface( |
|
fn=predict_cwe, |
|
inputs=gr.Textbox(lines=3, placeholder="Enter your commit message here..."), |
|
outputs=gr.Label(num_top_classes=5), |
|
title="CWE Prediction from Commit Message", |
|
description="Type a Git commit message and get the most likely CWE classes predicted by the model.", |
|
examples=[ |
|
["Fixed buffer overflow in input parsing"], |
|
["SQL injection possible in user login endpoint"] |
|
] |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|
|
|