Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,8 +57,17 @@ def plot_anomalies(df_test_value, data, anomalies):
|
|
| 57 |
ax.set_xlabel("Time")
|
| 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")
|
|
@@ -68,17 +77,11 @@ def master(file):
|
|
| 68 |
# predict
|
| 69 |
anomalies = get_anomalies(df_test_value)
|
| 70 |
# plot anomalous data points
|
| 71 |
-
plot2
|
| 72 |
-
#
|
| 73 |
-
anomalous_data_indices_str =
|
| 74 |
return format_output(plot2, anomalous_data_indices_str)
|
| 75 |
|
| 76 |
-
def format_output(plot, indices):
|
| 77 |
-
# Combine the plot and indices into a single output
|
| 78 |
-
fig, ax = plot
|
| 79 |
-
ax.text(0.5, -0.2, f"Anomalous Data Indices: {', '.join(indices)}", transform=ax.transAxes, fontsize=12, ha='center')
|
| 80 |
-
return fig
|
| 81 |
-
|
| 82 |
outputs = gr.outputs.Image()
|
| 83 |
|
| 84 |
iface = gr.Interface(
|
|
|
|
| 57 |
ax.set_xlabel("Time")
|
| 58 |
ax.set_ylabel("Value")
|
| 59 |
ax.set_title("Anomalous Data Points")
|
| 60 |
+
return fig
|
| 61 |
+
|
| 62 |
+
def format_output(plot, anomalous_data_indices_str):
|
| 63 |
+
if isinstance(plot, tuple):
|
| 64 |
+
fig, ax = plot
|
| 65 |
+
else:
|
| 66 |
+
fig = plot
|
| 67 |
+
ax = fig.axes[0]
|
| 68 |
+
ax.text(0, -0.1, "Anomalous Data Indices: " + anomalous_data_indices_str, transform=ax.transAxes)
|
| 69 |
+
return fig
|
| 70 |
+
|
| 71 |
def master(file):
|
| 72 |
# read file
|
| 73 |
data = pd.read_csv(file, parse_dates=True, index_col="timestamp")
|
|
|
|
| 77 |
# predict
|
| 78 |
anomalies = get_anomalies(df_test_value)
|
| 79 |
# plot anomalous data points
|
| 80 |
+
plot2 = plot_anomalies(df_test_value, data, anomalies)
|
| 81 |
+
# format output
|
| 82 |
+
anomalous_data_indices_str = ", ".join(map(str, np.where(anomalies)[0]))
|
| 83 |
return format_output(plot2, anomalous_data_indices_str)
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
outputs = gr.outputs.Image()
|
| 86 |
|
| 87 |
iface = gr.Interface(
|