Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mport gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
MODEL_NAME = "CIRCL/cwe-patch-vulnerability-classification-distilbert-base"
|
| 5 |
+
|
| 6 |
+
classifier = pipeline("text-classification", model=MODEL_NAME, return_all_scores=True)
|
| 7 |
+
|
| 8 |
+
def classify_cwe(text):
|
| 9 |
+
results = classifier(text)[0]
|
| 10 |
+
# Sort by confidence score descending
|
| 11 |
+
sorted_results = sorted(results, key=lambda x: x["score"], reverse=True)
|
| 12 |
+
return {res["label"]: round(res["score"], 4) for res in sorted_results[:5]}
|
| 13 |
+
|
| 14 |
+
interface = gr.Interface(
|
| 15 |
+
fn=classify_cwe,
|
| 16 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter vulnerability commit message..."),
|
| 17 |
+
outputs=gr.Label(num_top_classes=5),
|
| 18 |
+
title="CWE Vulnerability Classifier",
|
| 19 |
+
description="Enter a vulnerability commit message to predict the most likely CWE types."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Launch the Gradio app
|
| 23 |
+
interface.launch()
|