Download app.py from SureshKumarParamasivam/AlertNoiseReductionLatest: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/spaces/SureshKumarParamasivam/AlertNoiseReductionLatest/resolve/main/app.py
- Command line
-
hf download hf://spaces/SureshKumarParamasivam/AlertNoiseReductionLatest/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SureshKumarParamasivam/AlertNoiseReductionLatest/resolve/main/app.py
1.74 kB
| from typing import List, Dict | |
| import gradio as gr | |
| # Mock Alert | |
| alerts = [ | |
| {"id": 1, "type": "CPU_HIGH", "service": "payment-api", "severity": "warning"}, | |
| {"id": 2, "type": "LATENCY_SPIKE", "service": "payment-api", "severity": "critical"}, | |
| {"id": 3, "type": "DB_CONN_ERROR", "service": "payment-api", "severity": "critical"}, | |
| {"id": 4, "type": "DISK_USAGE", "service": "notification-service", "severity": "warning"}, | |
| ] | |
| # Agents | |
| def classify_alert(alert: Dict) -> str: | |
| if alert["severity"] == "critical": | |
| return "important" | |
| elif alert["severity"] == "info": | |
| return "noise" | |
| else: | |
| return "review" | |
| def filter_noise(alert_classification: str) -> bool: | |
| return alert_classification != "noise" | |
| def decide_escalation(alert: Dict, classification: str) -> str: | |
| if classification == "important": | |
| return f"🚨 Escalating incident for {alert['service']} to on-call." | |
| elif classification == "review": | |
| return f"📝 Logging alert for {alert['service']} for SRE review." | |
| else: | |
| return "" | |
| def narrate_summary(escalations: List[str]) -> str: | |
| if not escalations: | |
| return "All systems stable. No critical incidents." | |
| return "\n".join(escalations) | |
| def agentic_alert_handler(): | |
| escalations = [] | |
| for alert in alerts: | |
| classification = classify_alert(alert) | |
| if filter_noise(classification): | |
| action = decide_escalation(alert, classification) | |
| if action: | |
| escalations.append(action) | |
| summary = narrate_summary(escalations) | |
| return summary | |
| # Gradio Interface | |
| iface = gr.Interface(fn=agentic_alert_handler, inputs=[], outputs="text") | |
| iface.launch(server_name="0.0.0.0", server_port=7860) |