File size: 3,181 Bytes
b76f89c
aa395e0
 
b76f89c
a095866
b76f89c
 
a095866
b76f89c
 
 
 
 
 
 
aa395e0
b76f89c
 
 
 
aa395e0
 
b76f89c
aa395e0
b76f89c
a095866
 
 
 
 
 
 
 
 
 
b76f89c
 
 
 
aa395e0
b76f89c
aa395e0
b76f89c
aa395e0
b76f89c
 
 
aa395e0
b76f89c
 
aa395e0
 
 
 
b76f89c
aa395e0
b76f89c
 
aa395e0
a095866
b76f89c
 
a095866
aa395e0
 
a095866
aa395e0
 
a095866
b76f89c
 
 
 
 
aa395e0
 
 
 
 
 
 
 
 
 
 
 
b76f89c
 
a095866
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt

# App title and layout
st.set_page_config(page_title="AI Model Dashboard", layout="wide")

# Define models
models = [
    "Anomaly Detection",
    "Predictive Maintenance",
    "Cost Optimization",
    "Energy Efficiency"
]

# Initialize session state for agent status & errors
if "statuses" not in st.session_state:
    st.session_state.statuses = {model: "Running" for model in models}
if "error_logs" not in st.session_state:
    st.session_state.error_logs = {model: "" for model in models}
if "show_graphs" not in st.session_state:
    st.session_state.show_graphs = {model: False for model in models}

st.title("πŸ“Š AI Model & Agent Monitoring Dashboard")

# Function to handle status changes
def update_status(model, new_status):
    st.session_state.statuses[model] = new_status
    if new_status == "Error":
        st.session_state.error_logs[model] = f"Simulated error in {model} agent."
    elif new_status == "Resolved":
        st.session_state.show_graphs[model] = True
    elif new_status == "Running":
        st.session_state.show_graphs[model] = False

# Layout for models
for model in models:
    col1, col2, col3 = st.columns([2, 1, 1])
    
    # Model & Agent Status
    with col1:
        st.subheader(f"βš™οΈ {model} - Agent Status")
    
    # Display Status
    with col2:
        status = st.session_state.statuses[model]
        if status == "Running":
            st.success("βœ… Running - No Issues")
        elif status == "Error":
            st.error("❌ Error Occurred")
        elif status == "Resolving":
            st.warning("πŸ”„ Resolving Issue...")
        elif status == "Resolved":
            st.success("βœ” Resolved & Completed")

    # Control Buttons
    with col3:
        if status == "Running":
            if st.button(f"πŸ›‘ Simulate Error {model}", key=f"error_{model}"):
                update_status(model, "Error")
        elif status == "Error":
            if st.button(f"πŸ”„ Resolve & Restart {model}", key=f"resolve_{model}"):
                update_status(model, "Resolving")
        elif status == "Resolving":
            if st.button(f"βœ” Mark Resolved {model}", key=f"mark_resolved_{model}"):
                update_status(model, "Resolved")
        elif status == "Resolved":
            if st.button(f"β–Ά Restart {model}", key=f"restart_{model}"):
                update_status(model, "Running")

    # Show error logs if any
    if st.session_state.error_logs[model]:
        st.error(f"Error Log: {st.session_state.error_logs[model]}")

    # Display graph when resolved
    if st.session_state.show_graphs[model]:
        st.subheader(f"πŸ“Š {model} - Performance Graph")
        fig, ax = plt.subplots()
        x = np.arange(1, 11)
        y = np.random.rand(10) * 100  # Random performance data
        ax.plot(x, y, marker="o", linestyle="-", color="b")
        ax.set_xlabel("Time")
        ax.set_ylabel("Performance")
        ax.set_title(f"{model} - Performance Over Time")
        st.pyplot(fig)

    st.divider()

st.info("⚠ If an error occurs, only the affected agent stops. Resolve it before moving to the next.")