|
import streamlit as st |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
st.set_page_config(page_title="AI Model Dashboard", layout="wide") |
|
|
|
|
|
models = [ |
|
"Anomaly Detection", |
|
"Predictive Maintenance", |
|
"Cost Optimization", |
|
"Energy Efficiency" |
|
] |
|
|
|
|
|
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") |
|
|
|
|
|
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 |
|
|
|
|
|
for model in models: |
|
col1, col2, col3 = st.columns([2, 1, 1]) |
|
|
|
|
|
with col1: |
|
st.subheader(f"βοΈ {model} - Agent 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") |
|
|
|
|
|
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") |
|
|
|
|
|
if st.session_state.error_logs[model]: |
|
st.error(f"Error Log: {st.session_state.error_logs[model]}") |
|
|
|
|
|
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 |
|
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.") |