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