etechoptimist commited on
Commit
3714867
·
1 Parent(s): c10f136

distilbert/distilbert-base-uncased-finetuned-sst-2-english

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from transformers import pipeline
3
  import re
4
 
5
- def anomalies_detector(logs: str) -> list[tuple[int, str]]:
6
  """
7
  Detect anomalies in software logs using a Hugging Face transformer model.
8
  This function uses a specialized model trained to identify unusual patterns
@@ -19,12 +19,10 @@ def anomalies_detector(logs: str) -> list[tuple[int, str]]:
19
  Returns:
20
  list[tuple[int, str]]: List of tuples containing (line_number, anomalous_text)
21
  """
22
- # Initialize the text classification pipeline with a smaller, more reliable model
23
- classifier = pipeline(
24
- "text-classification",
25
- model="distilbert-base-uncased", # Using a smaller, more reliable model
26
- top_k=2 # Get both normal and anomalous probabilities
27
- )
28
 
29
  # Split logs into lines
30
  log_lines = logs.split('\n')
@@ -38,13 +36,9 @@ def anomalies_detector(logs: str) -> list[tuple[int, str]]:
38
  # Get classification result
39
  results = classifier(line)
40
 
41
- # Check if the line is classified as anomalous
42
- # The model returns probabilities for both classes
43
- for result in results:
44
- if result['label'] == 'LABEL_1' and result['score'] > 0.7: # LABEL_1 indicates potential anomaly
45
- anomalies.append((line_num, line))
46
- break
47
-
48
  return anomalies
49
 
50
  # Create a standard Gradio interface
 
2
  from transformers import pipeline
3
  import re
4
 
5
+ def anomalies_detector(logs: str) -> list[str]:
6
  """
7
  Detect anomalies in software logs using a Hugging Face transformer model.
8
  This function uses a specialized model trained to identify unusual patterns
 
19
  Returns:
20
  list[tuple[int, str]]: List of tuples containing (line_number, anomalous_text)
21
  """
22
+ # Initialize the text classification pipeline with a proper classification model
23
+ classifier = pipeline("text-classification",
24
+ model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
25
+
 
 
26
 
27
  # Split logs into lines
28
  log_lines = logs.split('\n')
 
36
  # Get classification result
37
  results = classifier(line)
38
 
39
+
40
+ for log, res in zip(logs, results):
41
+ anomalies.append(f"{log} => {res}")
 
 
 
 
42
  return anomalies
43
 
44
  # Create a standard Gradio interface