| import gradio as gr |
| from transformers import pipeline |
| import re |
|
|
| def anomalies_detector(logs: str) -> list[str]: |
| """ |
| Detect anomalies in software logs using a Hugging Face transformer model. |
| This function uses a specialized model trained to identify unusual patterns |
| in system logs, such as: |
| - Error messages |
| - Unusual system states |
| - Security-related events |
| - Performance anomalies |
| - Unexpected behavior patterns |
| |
| Args: |
| logs (str): The input text containing log entries |
| |
| Returns: |
| list[tuple[int, str]]: List of tuples containing (line_number, anomalous_text) |
| """ |
| |
| classifier = pipeline("text-classification", |
| model="distilbert/distilbert-base-uncased-finetuned-sst-2-english") |
|
|
| |
| |
| log_lines = logs.split('\n') |
| anomalies = [] |
| |
| |
| for line_num, line in enumerate(log_lines, 1): |
| if not line.strip(): |
| continue |
| |
| |
| results = classifier(line) |
| |
| |
| for log, res in zip(logs, results): |
| anomalies.append(f"{log} => {res}") |
| return anomalies |
|
|
| |
| demo = gr.Interface( |
| fn=anomalies_detector, |
| inputs="textbox", |
| outputs="text", |
| title="Log Anomaly Detector", |
| description="Enter log entries to detect anomalous patterns using BERT Model. The system will identify unusual patterns, errors, and potential issues in your logs." |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch(mcp_server=True, share=True) |
|
|