elselse commited on
Commit
3b1fc96
·
verified ·
1 Parent(s): 3297b4f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
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()