Update app.py
Browse files
app.py
CHANGED
|
@@ -13,29 +13,29 @@ import tempfile
|
|
| 13 |
# Configure logging to match the log format
|
| 14 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s,%(msecs)03d - %(levelname)s - %(message)s')
|
| 15 |
|
| 16 |
-
# CSS styling for the Gradio interface
|
| 17 |
css = """
|
| 18 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
|
| 19 |
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');
|
| 20 |
|
| 21 |
body {
|
| 22 |
font-family: 'Roboto', sans-serif;
|
| 23 |
-
background-color: #
|
| 24 |
-
color: #
|
| 25 |
margin: 0;
|
| 26 |
padding: 20px;
|
| 27 |
}
|
| 28 |
|
| 29 |
h1 {
|
| 30 |
-
color: #
|
| 31 |
text-align: center;
|
| 32 |
font-size: 2rem;
|
| 33 |
margin-bottom: 30px;
|
| 34 |
}
|
| 35 |
|
| 36 |
.gr-button {
|
| 37 |
-
background-color: #
|
| 38 |
-
color:
|
| 39 |
border: none;
|
| 40 |
border-radius: 8px;
|
| 41 |
padding: 12px 24px;
|
|
@@ -44,7 +44,7 @@ h1 {
|
|
| 44 |
}
|
| 45 |
|
| 46 |
.gr-button:hover {
|
| 47 |
-
background-color: #
|
| 48 |
}
|
| 49 |
|
| 50 |
.dashboard-container {
|
|
@@ -56,9 +56,10 @@ h1 {
|
|
| 56 |
}
|
| 57 |
|
| 58 |
.card {
|
| 59 |
-
background-color:
|
|
|
|
| 60 |
border-radius: 10px;
|
| 61 |
-
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.
|
| 62 |
padding: 20px;
|
| 63 |
transition: transform 0.2s;
|
| 64 |
}
|
|
@@ -68,7 +69,7 @@ h1 {
|
|
| 68 |
}
|
| 69 |
|
| 70 |
.card h2 {
|
| 71 |
-
color: #
|
| 72 |
font-size: 1.2rem;
|
| 73 |
margin-top: 0;
|
| 74 |
margin-bottom: 15px;
|
|
@@ -78,12 +79,11 @@ h1 {
|
|
| 78 |
}
|
| 79 |
|
| 80 |
.device-card {
|
| 81 |
-
|
| 82 |
-
border-left: 5px solid #1E40AF;
|
| 83 |
}
|
| 84 |
|
| 85 |
.alert-card {
|
| 86 |
-
border-left: 5px solid #
|
| 87 |
}
|
| 88 |
|
| 89 |
.chart-container {
|
|
@@ -107,8 +107,8 @@ h1 {
|
|
| 107 |
}
|
| 108 |
|
| 109 |
.flowchart-step {
|
| 110 |
-
background-color: #
|
| 111 |
-
border-left: 5px solid #
|
| 112 |
padding: 15px;
|
| 113 |
border-radius: 5px;
|
| 114 |
position: relative;
|
|
@@ -121,22 +121,22 @@ h1 {
|
|
| 121 |
left: 50%;
|
| 122 |
transform: translateX(-50%);
|
| 123 |
font-size: 20px;
|
| 124 |
-
color: #
|
| 125 |
}
|
| 126 |
|
| 127 |
.alert-urgent {
|
| 128 |
-
color: #
|
| 129 |
font-weight: bold;
|
| 130 |
}
|
| 131 |
|
| 132 |
.alert-upcoming {
|
| 133 |
-
color: #
|
| 134 |
font-weight: bold;
|
| 135 |
}
|
| 136 |
|
| 137 |
.recommendation {
|
| 138 |
font-style: italic;
|
| 139 |
-
color: #
|
| 140 |
margin-top: 10px;
|
| 141 |
}
|
| 142 |
|
|
@@ -150,7 +150,7 @@ h1 {
|
|
| 150 |
|
| 151 |
.anomaly-unusual {
|
| 152 |
background-color: #FEE2E2;
|
| 153 |
-
color: #
|
| 154 |
}
|
| 155 |
|
| 156 |
.anomaly-normal {
|
|
@@ -162,8 +162,8 @@ h1 {
|
|
| 162 |
display: inline-flex;
|
| 163 |
align-items: center;
|
| 164 |
gap: 8px;
|
| 165 |
-
background-color: #
|
| 166 |
-
color:
|
| 167 |
padding: 10px 20px;
|
| 168 |
border-radius: 8px;
|
| 169 |
text-decoration: none;
|
|
@@ -172,7 +172,27 @@ h1 {
|
|
| 172 |
}
|
| 173 |
|
| 174 |
.download-button:hover {
|
| 175 |
-
background-color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
}
|
| 177 |
|
| 178 |
/* Responsive Design */
|
|
@@ -416,8 +436,8 @@ def generate_usage_plot(df):
|
|
| 416 |
"""
|
| 417 |
try:
|
| 418 |
plt.figure(figsize=(12, 6))
|
| 419 |
-
# Define colors for statuses
|
| 420 |
-
status_colors = {'Active': '#
|
| 421 |
for status in df['status'].unique():
|
| 422 |
subset = df[df['status'] == status]
|
| 423 |
plt.bar(
|
|
@@ -426,11 +446,14 @@ def generate_usage_plot(df):
|
|
| 426 |
label=status,
|
| 427 |
color=status_colors.get(status, '#6B7280')
|
| 428 |
)
|
| 429 |
-
plt.xlabel("Equipment (Status)", fontsize=12)
|
| 430 |
-
plt.ylabel("Usage Count", fontsize=12)
|
| 431 |
-
plt.title("Device Usage Overview", fontsize=14, color='#
|
| 432 |
plt.legend(title="Status")
|
| 433 |
-
plt.xticks(rotation=45, ha='right')
|
|
|
|
|
|
|
|
|
|
| 434 |
plt.tight_layout()
|
| 435 |
|
| 436 |
# Save plot to temporary file
|
|
|
|
| 13 |
# Configure logging to match the log format
|
| 14 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s,%(msecs)03d - %(levelname)s - %(message)s')
|
| 15 |
|
| 16 |
+
# CSS styling for the Gradio interface with a dark theme and high-contrast text
|
| 17 |
css = """
|
| 18 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
|
| 19 |
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');
|
| 20 |
|
| 21 |
body {
|
| 22 |
font-family: 'Roboto', sans-serif;
|
| 23 |
+
background-color: #1F2937;
|
| 24 |
+
color: #D1D5DB;
|
| 25 |
margin: 0;
|
| 26 |
padding: 20px;
|
| 27 |
}
|
| 28 |
|
| 29 |
h1 {
|
| 30 |
+
color: #FFFFFF;
|
| 31 |
text-align: center;
|
| 32 |
font-size: 2rem;
|
| 33 |
margin-bottom: 30px;
|
| 34 |
}
|
| 35 |
|
| 36 |
.gr-button {
|
| 37 |
+
background-color: #2DD4BF;
|
| 38 |
+
color: #1F2937;
|
| 39 |
border: none;
|
| 40 |
border-radius: 8px;
|
| 41 |
padding: 12px 24px;
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
.gr-button:hover {
|
| 47 |
+
background-color: #26A69A;
|
| 48 |
}
|
| 49 |
|
| 50 |
.dashboard-container {
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
.card {
|
| 59 |
+
background-color: #374151;
|
| 60 |
+
border: 1px solid #4B5563;
|
| 61 |
border-radius: 10px;
|
| 62 |
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
|
| 63 |
padding: 20px;
|
| 64 |
transition: transform 0.2s;
|
| 65 |
}
|
|
|
|
| 69 |
}
|
| 70 |
|
| 71 |
.card h2 {
|
| 72 |
+
color: #FFFFFF;
|
| 73 |
font-size: 1.2rem;
|
| 74 |
margin-top: 0;
|
| 75 |
margin-bottom: 15px;
|
|
|
|
| 79 |
}
|
| 80 |
|
| 81 |
.device-card {
|
| 82 |
+
border-left: 5px solid #2DD4BF;
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
.alert-card {
|
| 86 |
+
border-left: 5px solid #F87171;
|
| 87 |
}
|
| 88 |
|
| 89 |
.chart-container {
|
|
|
|
| 107 |
}
|
| 108 |
|
| 109 |
.flowchart-step {
|
| 110 |
+
background-color: #4B5563;
|
| 111 |
+
border-left: 5px solid #2DD4BF;
|
| 112 |
padding: 15px;
|
| 113 |
border-radius: 5px;
|
| 114 |
position: relative;
|
|
|
|
| 121 |
left: 50%;
|
| 122 |
transform: translateX(-50%);
|
| 123 |
font-size: 20px;
|
| 124 |
+
color: #2DD4BF;
|
| 125 |
}
|
| 126 |
|
| 127 |
.alert-urgent {
|
| 128 |
+
color: #F87171;
|
| 129 |
font-weight: bold;
|
| 130 |
}
|
| 131 |
|
| 132 |
.alert-upcoming {
|
| 133 |
+
color: #FBBF24;
|
| 134 |
font-weight: bold;
|
| 135 |
}
|
| 136 |
|
| 137 |
.recommendation {
|
| 138 |
font-style: italic;
|
| 139 |
+
color: #9CA3AF;
|
| 140 |
margin-top: 10px;
|
| 141 |
}
|
| 142 |
|
|
|
|
| 150 |
|
| 151 |
.anomaly-unusual {
|
| 152 |
background-color: #FEE2E2;
|
| 153 |
+
color: #F87171;
|
| 154 |
}
|
| 155 |
|
| 156 |
.anomaly-normal {
|
|
|
|
| 162 |
display: inline-flex;
|
| 163 |
align-items: center;
|
| 164 |
gap: 8px;
|
| 165 |
+
background-color: #2DD4BF;
|
| 166 |
+
color: #1F2937;
|
| 167 |
padding: 10px 20px;
|
| 168 |
border-radius: 8px;
|
| 169 |
text-decoration: none;
|
|
|
|
| 172 |
}
|
| 173 |
|
| 174 |
.download-button:hover {
|
| 175 |
+
background-color: #26A69A;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/* Ensure text in dataframe is readable */
|
| 179 |
+
.dataframe-container table {
|
| 180 |
+
color: #D1D5DB;
|
| 181 |
+
background-color: #374151;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.dataframe-container thead th {
|
| 185 |
+
background-color: #4B5563;
|
| 186 |
+
color: #FFFFFF;
|
| 187 |
+
font-weight: 500;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.dataframe-container tbody tr:nth-child(even) {
|
| 191 |
+
background-color: #4B5563;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.dataframe-container tbody tr:hover {
|
| 195 |
+
background-color: #6B7280;
|
| 196 |
}
|
| 197 |
|
| 198 |
/* Responsive Design */
|
|
|
|
| 436 |
"""
|
| 437 |
try:
|
| 438 |
plt.figure(figsize=(12, 6))
|
| 439 |
+
# Define colors for statuses (adjusted for dark theme visibility)
|
| 440 |
+
status_colors = {'Active': '#2DD4BF', 'Inactive': '#F87171', 'Down': '#FBBF24', 'Online': '#10B981'}
|
| 441 |
for status in df['status'].unique():
|
| 442 |
subset = df[df['status'] == status]
|
| 443 |
plt.bar(
|
|
|
|
| 446 |
label=status,
|
| 447 |
color=status_colors.get(status, '#6B7280')
|
| 448 |
)
|
| 449 |
+
plt.xlabel("Equipment (Status)", fontsize=12, color='#D1D5DB')
|
| 450 |
+
plt.ylabel("Usage Count", fontsize=12, color='#D1D5DB')
|
| 451 |
+
plt.title("Device Usage Overview", fontsize=14, color='#FFFFFF')
|
| 452 |
plt.legend(title="Status")
|
| 453 |
+
plt.xticks(rotation=45, ha='right', color='#D1D5DB')
|
| 454 |
+
plt.yticks(color='#D1D5DB')
|
| 455 |
+
plt.gca().set_facecolor('#374151')
|
| 456 |
+
plt.gcf().set_facecolor('#1F2937')
|
| 457 |
plt.tight_layout()
|
| 458 |
|
| 459 |
# Save plot to temporary file
|