elselse commited on
Commit
9b0878e
·
verified ·
1 Parent(s): 2c3bbb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -14
app.py CHANGED
@@ -1,23 +1,13 @@
1
  import gradio as gr
2
  import json
3
  from transformers import pipeline
4
- import torch
5
- import random
6
- import numpy as np
7
-
8
- torch.manual_seed(42)
9
- random.seed(42)
10
- np.random.seed(42)
11
-
12
- torch.use_deterministic_algorithms(True)
13
 
14
  # Load Hugging Face model (text classification)
15
  classifier = pipeline(
16
  task="text-classification",
17
  model="CIRCL/cwe-parent-vulnerability-classification-roberta-base",
18
- top_k=None
19
  )
20
- classifier.model.eval()
21
 
22
  # Load child-to-parent mapping
23
  with open("child_to_parent_mapping.json", "r") as f:
@@ -29,9 +19,6 @@ def predict_cwe(commit_message: str):
29
  """
30
  results = classifier(commit_message)[0]
31
  sorted_results = sorted(results, key=lambda x: x["score"], reverse=True)
32
-
33
- threshold = 0.2
34
- filtered_results = [item for item in sorted_results if item["score"] >= threshold]
35
 
36
  # Map predictions to parent CWE (if available)
37
  mapped_results = {}
@@ -54,6 +41,8 @@ demo = gr.Interface(
54
  ["Fixed buffer overflow in input parsing"],
55
  ["SQL injection possible in login flow"],
56
  ["Improved input validation to prevent XSS"],
 
 
57
  ]
58
  )
59
 
 
1
  import gradio as gr
2
  import json
3
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
4
 
5
  # Load Hugging Face model (text classification)
6
  classifier = pipeline(
7
  task="text-classification",
8
  model="CIRCL/cwe-parent-vulnerability-classification-roberta-base",
9
+ return_all_scores=True
10
  )
 
11
 
12
  # Load child-to-parent mapping
13
  with open("child_to_parent_mapping.json", "r") as f:
 
19
  """
20
  results = classifier(commit_message)[0]
21
  sorted_results = sorted(results, key=lambda x: x["score"], reverse=True)
 
 
 
22
 
23
  # Map predictions to parent CWE (if available)
24
  mapped_results = {}
 
41
  ["Fixed buffer overflow in input parsing"],
42
  ["SQL injection possible in login flow"],
43
  ["Improved input validation to prevent XSS"],
44
+ ["Added try/catch to avoid null pointer crash"],
45
+ ["Patched race condition in thread lock logic"]
46
  ]
47
  )
48