Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,14 @@
|
|
|
|
|
|
1 |
import pandas as pd
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
from datasets import load_dataset
|
|
|
|
|
|
|
5 |
|
6 |
LOGS_DATASET_URI = 'pgurazada1/machine-failure-mlops-demo-logs'
|
7 |
|
@@ -12,14 +19,54 @@ def get_data():
|
|
12 |
Pull the data into a dataframe
|
13 |
"""
|
14 |
data = load_dataset(LOGS_DATASET_URI)
|
15 |
-
sample_df = data['train'].to_pandas().sample(
|
16 |
|
17 |
return sample_df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
with gr.Blocks() as demo:
|
20 |
-
gr.Markdown("Real-time Monitoring Dashboard")
|
|
|
|
|
|
|
21 |
with gr.Row():
|
22 |
with gr.Column():
|
23 |
-
gr.DataFrame(get_data)
|
|
|
|
|
24 |
|
25 |
demo.queue().launch()
|
|
|
1 |
+
import time
|
2 |
+
|
3 |
import pandas as pd
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import seaborn as sns
|
6 |
import gradio as gr
|
7 |
|
8 |
from datasets import load_dataset
|
9 |
+
from sklearn.datasets import fetch_openml
|
10 |
+
from sklearn.model_selection import train_test_split
|
11 |
+
from sklearn.metrics import classification_report
|
12 |
|
13 |
LOGS_DATASET_URI = 'pgurazada1/machine-failure-mlops-demo-logs'
|
14 |
|
|
|
19 |
Pull the data into a dataframe
|
20 |
"""
|
21 |
data = load_dataset(LOGS_DATASET_URI)
|
22 |
+
sample_df = data['train'].to_pandas().sample(100)
|
23 |
|
24 |
return sample_df
|
25 |
+
|
26 |
+
def load_training_data():
|
27 |
+
dataset = fetch_openml(data_id=42890, as_frame=True, parser="auto")
|
28 |
+
data_df = dataset.data
|
29 |
+
|
30 |
+
target = 'Machine failure'
|
31 |
+
numeric_features = [
|
32 |
+
'Air temperature [K]',
|
33 |
+
'Process temperature [K]',
|
34 |
+
'Rotational speed [rpm]',
|
35 |
+
'Torque [Nm]',
|
36 |
+
'Tool wear [min]'
|
37 |
+
]
|
38 |
+
|
39 |
+
categorical_features = ['Type']
|
40 |
+
|
41 |
+
X = data_df[numeric_features + categorical_features]
|
42 |
+
y = data_df[target]
|
43 |
+
|
44 |
+
Xtrain, Xtest, ytrain, ytest = train_test_split(
|
45 |
+
X, y,
|
46 |
+
test_size=0.2,
|
47 |
+
random_state=42
|
48 |
+
)
|
49 |
+
|
50 |
+
return Xtrain, ytrain
|
51 |
+
|
52 |
+
def check_model_drift():
|
53 |
+
sample_df = get_data()
|
54 |
+
p_pos_label_training_data = 0.03475
|
55 |
+
training_data_size = 8000
|
56 |
+
p_pos_label_sample_logs = sample_df.prediction.value_counts()
|
57 |
+
|
58 |
+
return p_pos_label_sample_logs
|
59 |
+
|
60 |
|
61 |
with gr.Blocks() as demo:
|
62 |
+
gr.Markdown("# Real-time Monitoring Dashboard")
|
63 |
+
|
64 |
+
gr.Markdown("Snapshot of live data")
|
65 |
+
|
66 |
with gr.Row():
|
67 |
with gr.Column():
|
68 |
+
gr.DataFrame(get_data, every=5)
|
69 |
+
with gr.Column():
|
70 |
+
gr.TextBox(f"Data refreshed at {time.time()}", every=5)
|
71 |
|
72 |
demo.queue().launch()
|