Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,34 +58,7 @@ def plot_anomalies(df_test_value, data, anomalies):
|
|
| 58 |
ax.set_ylabel("Value")
|
| 59 |
ax.set_title("Anomalous Data Points")
|
| 60 |
return fig
|
| 61 |
-
|
| 62 |
-
def format_output(plot, indices):
|
| 63 |
-
if plot is None:
|
| 64 |
-
return None, None
|
| 65 |
-
|
| 66 |
-
# Create a new figure and axis for the combined output
|
| 67 |
-
fig_combined = plt.figure(figsize=(12, 8))
|
| 68 |
-
gs = fig_combined.add_gridspec(2, 1, height_ratios=[6, 1])
|
| 69 |
-
|
| 70 |
-
# Add the plot to the top axis
|
| 71 |
-
ax_plot = fig_combined.add_subplot(gs[0])
|
| 72 |
-
if isinstance(plot, tuple):
|
| 73 |
-
fig, ax = plot
|
| 74 |
-
ax.plot()
|
| 75 |
-
ax_plot.imshow(fig.canvas.renderer.buffer_rgba())
|
| 76 |
-
else:
|
| 77 |
-
ax_plot.imshow(plot)
|
| 78 |
-
ax_plot.axis('off')
|
| 79 |
-
|
| 80 |
-
# Add the text to the bottom axis
|
| 81 |
-
ax_text = fig_combined.add_subplot(gs[1])
|
| 82 |
-
ax_text.text(0.5, 0, f"Anomalous Data Indices: {', '.join(indices)}", fontsize=12, ha='center')
|
| 83 |
-
ax_text.axis('off')
|
| 84 |
-
|
| 85 |
-
return fig_combined, None
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
def master(file):
|
| 90 |
# read file
|
| 91 |
data = pd.read_csv(file, parse_dates=True, index_col="timestamp")
|
|
@@ -94,11 +67,9 @@ def master(file):
|
|
| 94 |
plot1 = plot_test_data(df_test_value)
|
| 95 |
# predict
|
| 96 |
anomalies = get_anomalies(df_test_value)
|
| 97 |
-
#
|
| 98 |
plot2 = plot_anomalies(df_test_value, data, anomalies)
|
| 99 |
-
|
| 100 |
-
anomalous_data_indices_str = ", ".join(map(str, np.where(anomalies)[0]))
|
| 101 |
-
return format_output(plot2, anomalous_data_indices_str)
|
| 102 |
|
| 103 |
outputs = gr.outputs.Image()
|
| 104 |
|
|
@@ -111,4 +82,4 @@ iface = gr.Interface(
|
|
| 111 |
description="Anomaly detection of timeseries data."
|
| 112 |
)
|
| 113 |
|
| 114 |
-
iface.launch()
|
|
|
|
| 58 |
ax.set_ylabel("Value")
|
| 59 |
ax.set_title("Anomalous Data Points")
|
| 60 |
return fig
|
| 61 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def master(file):
|
| 63 |
# read file
|
| 64 |
data = pd.read_csv(file, parse_dates=True, index_col="timestamp")
|
|
|
|
| 67 |
plot1 = plot_test_data(df_test_value)
|
| 68 |
# predict
|
| 69 |
anomalies = get_anomalies(df_test_value)
|
| 70 |
+
#plot anomalous data points
|
| 71 |
plot2 = plot_anomalies(df_test_value, data, anomalies)
|
| 72 |
+
return plot2
|
|
|
|
|
|
|
| 73 |
|
| 74 |
outputs = gr.outputs.Image()
|
| 75 |
|
|
|
|
| 82 |
description="Anomaly detection of timeseries data."
|
| 83 |
)
|
| 84 |
|
| 85 |
+
iface.launch()
|