DHEIVER commited on
Commit
4c5678a
·
1 Parent(s): 55f60c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -68,10 +68,18 @@ def master(file):
68
  # predict
69
  anomalies = get_anomalies(df_test_value)
70
  # plot anomalous data points
71
- plot2, anomalous_indices = plot_anomalies(df_test_value, data, anomalies)
72
- return plot2, anomalous_indices
 
 
73
 
74
- outputs = [gr.outputs.Image(), "text"]
 
 
 
 
 
 
75
 
76
  iface = gr.Interface(
77
  fn=master,
@@ -82,5 +90,9 @@ iface = gr.Interface(
82
  description="Anomaly detection of timeseries data."
83
  )
84
 
85
- # Display the interface
86
  iface.launch()
 
 
 
 
 
 
68
  # predict
69
  anomalies = get_anomalies(df_test_value)
70
  # plot anomalous data points
71
+ plot2, anomalous_data_indices = plot_anomalies(df_test_value, data, anomalies)
72
+ # convert indices to string
73
+ anomalous_data_indices_str = [str(idx) for idx in anomalous_data_indices]
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(
85
  fn=master,
 
90
  description="Anomaly detection of timeseries data."
91
  )
92
 
 
93
  iface.launch()
94
+ ```
95
+
96
+ With this code, the interface will display the plot of the anomalous data points along with the indices of the anomalous data points below the plot. The user can upload a CSV file, and the interface will generate the plot and detect the anomalies in the timeseries data.
97
+
98
+ I hope this helps! Let me know if you have any further questions.