Spaces:
Runtime error
Runtime error
Download pipeline/agent.py from AgenticPrediction/Agentic_Predictive_Maintenance: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/AgenticPrediction/Agentic_Predictive_Maintenance/resolve/main/pipeline/agent.py
- Command line
-
hf download hf://spaces/AgenticPrediction/Agentic_Predictive_Maintenance/pipeline/agent.py
-
curl -L -o agent.py https://huggingface.co/spaces/AgenticPrediction/Agentic_Predictive_Maintenance/resolve/main/pipeline/agent.py
1.59 kB
| def generate_agent_actions(fig, feature_map, red_nodes, central_node, scores, threshold=0.7): | |
| """ | |
| Suggests actions based on node anomaly scores and graph structure. | |
| Args: | |
| fig (matplotlib.Figure): The plotted graph figure. | |
| feature_map (list): List mapping node indices to feature names. | |
| red_nodes (list): Indices of detected anomalous nodes. | |
| central_node (int): The node with highest anomaly score. | |
| scores (np.ndarray): Anomaly score array per node. | |
| threshold (float): Minimum score to trigger an action. | |
| Returns: | |
| list of str: Recommended actions for inspection. | |
| """ | |
| actions = [] | |
| # Get name of central node | |
| try: | |
| central_name = feature_map[central_node] | |
| except IndexError: | |
| central_name = f"Node {central_node}" | |
| central_score = scores[central_node] | |
| actions.append(f"🔍 Investigate central anomaly node: {central_name} (score: {central_score:.2f})") | |
| for node in red_nodes: | |
| if node == central_node: | |
| continue | |
| try: | |
| node_name = feature_map[node] | |
| except IndexError: | |
| node_name = f"Node {node}" | |
| node_score = scores[node] | |
| if node_score > threshold: | |
| actions.append(f"🔧 Inspect connected node: {node_name} (score: {node_score:.2f})") | |
| else: | |
| actions.append(f"ℹ️ Monitor node: {node_name} (score: {node_score:.2f})") | |
| # Sort actions by score | |
| actions.sort(key=lambda x: float(x.split("score:")[-1].rstrip(")").strip()), reverse=True) | |
| return actions | |