Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,74 @@
|
|
|
|
1 |
import sys
|
2 |
-
import os
|
3 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
4 |
-
|
5 |
import streamlit as st
|
6 |
import pandas as pd
|
7 |
from utils.load_data import load_logs
|
8 |
from utils.visualize import plot_usage
|
9 |
from utils.report import generate_pdf
|
10 |
-
from models.
|
11 |
from utils.amc import upcoming_amc_devices
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
st.set_page_config(page_title="LabOps Dashboard", layout="wide")
|
14 |
st.title("π Multi-Device LabOps Dashboard")
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
if uploaded_files:
|
19 |
-
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
try:
|
29 |
anomalies = detect_anomalies(df)
|
30 |
st.dataframe(anomalies)
|
31 |
-
except Exception as e:
|
32 |
-
st.error(f"Failed to compute anomalies: {e}")
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
try:
|
37 |
amc_df = upcoming_amc_devices(df)
|
38 |
st.dataframe(amc_df)
|
39 |
-
|
40 |
-
st.
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```
|
2 |
import sys
|
|
|
|
|
|
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
5 |
from utils.load_data import load_logs
|
6 |
from utils.visualize import plot_usage
|
7 |
from utils.report import generate_pdf
|
8 |
+
from models.anomaly_detection import detect_anomalies
|
9 |
from utils.amc import upcoming_amc_devices
|
10 |
+
import logging
|
11 |
+
|
12 |
+
# Configure logging
|
13 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
14 |
+
logger = logging.getLogger(__name__)
|
15 |
+
|
16 |
+
# Streamlit app setup
|
17 |
+
try:
|
18 |
+
st.set_page_config(page_title="LabOps Dashboard", layout="wide")
|
19 |
+
logger.info("Streamlit page configuration set successfully.")
|
20 |
+
except Exception as e:
|
21 |
+
logger.error(f"Failed to configure Streamlit: {e}")
|
22 |
+
raise
|
23 |
|
|
|
24 |
st.title("π Multi-Device LabOps Dashboard")
|
25 |
|
26 |
+
# File uploader
|
27 |
+
try:
|
28 |
+
uploaded_files = st.file_uploader("Upload Device Logs (CSV)", accept_multiple_files=True, type=["csv"])
|
29 |
+
logger.info(f"Received {len(uploaded_files)} uploaded files.")
|
30 |
+
except Exception as e:
|
31 |
+
logger.error(f"File uploader error: {e}")
|
32 |
+
st.error(f"Failed to initialize file uploader: {e}")
|
33 |
|
34 |
if uploaded_files:
|
35 |
+
try:
|
36 |
+
df = load_logs(uploaded_files)
|
37 |
+
logger.info(f"Loaded {len(df)} log records from uploaded files.")
|
38 |
|
39 |
+
st.subheader("π Uploaded Logs")
|
40 |
+
st.dataframe(df.head())
|
41 |
|
42 |
+
st.subheader("π Daily Usage Chart")
|
43 |
+
fig = plot_usage(df)
|
44 |
+
st.pyplot(fig)
|
45 |
|
46 |
+
st.subheader("π¨ Detected Anomalies")
|
|
|
47 |
anomalies = detect_anomalies(df)
|
48 |
st.dataframe(anomalies)
|
|
|
|
|
49 |
|
50 |
+
st.subheader("π Upcoming AMC Devices")
|
51 |
+
if "amc_expiry" in df.columns:
|
|
|
52 |
amc_df = upcoming_amc_devices(df)
|
53 |
st.dataframe(amc_df)
|
54 |
+
else:
|
55 |
+
st.info("Column `amc_expiry` not found in uploaded data.")
|
56 |
+
logger.warning("Missing `amc_expiry` column in data.")
|
57 |
+
|
58 |
+
if st.button("π Generate PDF Report"):
|
59 |
+
pdf_path = generate_pdf(df)
|
60 |
+
with open(pdf_path, "rb") as f:
|
61 |
+
st.download_button("Download PDF", f, file_name="labops_report.pdf", mime="application/pdf")
|
62 |
+
logger.info("PDF report generated and offered for download.")
|
63 |
+
|
64 |
+
except Exception as e:
|
65 |
+
logger.error(f"Error processing uploaded files: {e}")
|
66 |
+
st.error(f"Failed to process data: {e}")
|
67 |
+
|
68 |
+
if __name__ == "__main__":
|
69 |
+
try:
|
70 |
+
logger.info("Application starting...")
|
71 |
+
except Exception as e:
|
72 |
+
logger.error(f"Application failed to start: {e}")
|
73 |
+
raise
|
74 |
+
```
|