Spaces:
Running
Running
added yield
Browse files
app.py
CHANGED
|
@@ -13,9 +13,16 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
| 13 |
OUT_PATH ="./savedPredictions/results.csv"
|
| 14 |
|
| 15 |
def dataProcessing(file, timestamp_column:str=None):
|
|
|
|
| 16 |
if os.path.exists(OUT_PATH):
|
| 17 |
os.remove(OUT_PATH)
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
try:
|
| 21 |
validateData(file, timestamp_column)
|
|
@@ -29,12 +36,12 @@ def dataProcessing(file, timestamp_column:str=None):
|
|
| 29 |
df.to_csv(OUT_PATH, index=False)
|
| 30 |
|
| 31 |
if fig is not None:
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
-
|
| 38 |
|
| 39 |
|
| 40 |
if os.path.exists(OUT_PATH):
|
|
@@ -55,13 +62,13 @@ with gr.Blocks(title="Time series anomaly detection with Chronos2") as demo:
|
|
| 55 |
and visualize the detected anomalies using the Chronos2 pipeline.
|
| 56 |
|
| 57 |
## Instructions
|
| 58 |
-
1. Click on the
|
| 59 |
-
- "timestamp": the timestamp column of your data (e.g., "2023-01-01 00:00:00"). It is optional
|
| 60 |
-
- "values": the columns containing the values of the time series data. They can be named as you wish. At least one column of values is required.
|
| 61 |
2. Answer the question about the timestamp in your data to help the model understand the temporal structure of your data.
|
| 62 |
- if present, you will need to specify the column name of the timestamp in your data.
|
| 63 |
- Otherwise, no need to do anything, just mark No.
|
| 64 |
-
3. Click on the
|
| 65 |
4. If the number of series is reasonably small, we will plot the original time series along with the detected anomalies.
|
| 66 |
5. We will provide a downloadable CSV file containing the original time series data along with an additional column indicating whether each point is an anomaly or not. We will label as 1 anomalies, as 0 normal points and as -1 the points for which we don't have a prediction because they are before the minimum length required by the model.
|
| 67 |
|
|
@@ -98,18 +105,6 @@ with gr.Blocks(title="Time series anomaly detection with Chronos2") as demo:
|
|
| 98 |
|
| 99 |
processing_msg = gr.Markdown("⏳ Processing file, please wait...", visible=False)
|
| 100 |
|
| 101 |
-
detect_button.click(
|
| 102 |
-
lambda : gr.update(visible=True),
|
| 103 |
-
inputs=None,
|
| 104 |
-
outputs=processing_msg
|
| 105 |
-
)
|
| 106 |
-
|
| 107 |
-
detect_button.click(
|
| 108 |
-
lambda : gr.update(visible=False, value=""),
|
| 109 |
-
inputs=None,
|
| 110 |
-
outputs=[plot_output, download_output, errorHandler]
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
detect_button.click(
|
| 114 |
lambda file, timestamp_question, timestamp_column:
|
| 115 |
dataProcessing(
|
|
@@ -117,14 +112,7 @@ with gr.Blocks(title="Time series anomaly detection with Chronos2") as demo:
|
|
| 117 |
timestamp_column if timestamp_question == "Yes" else None
|
| 118 |
),
|
| 119 |
inputs=[file_input, timestamp_question, timestamp_column_input],
|
| 120 |
-
outputs=[plot_output, download_output, errorHandler]
|
| 121 |
)
|
| 122 |
|
| 123 |
-
detect_button.click(
|
| 124 |
-
lambda : gr.update(visible=False),
|
| 125 |
-
inputs=None,
|
| 126 |
-
outputs=processing_msg
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
|
| 130 |
demo.launch(share=True)
|
|
|
|
| 13 |
OUT_PATH ="./savedPredictions/results.csv"
|
| 14 |
|
| 15 |
def dataProcessing(file, timestamp_column:str=None):
|
| 16 |
+
global chronos2
|
| 17 |
if os.path.exists(OUT_PATH):
|
| 18 |
os.remove(OUT_PATH)
|
| 19 |
+
|
| 20 |
+
yield (
|
| 21 |
+
gr.update(visible=True, value="⏳ Processing file, please wait..."), # processing_msg
|
| 22 |
+
gr.update(visible=False), # plot_output
|
| 23 |
+
gr.update(visible=False), # download_output
|
| 24 |
+
gr.update(visible=False, value="") # errorHandler
|
| 25 |
+
)
|
| 26 |
|
| 27 |
try:
|
| 28 |
validateData(file, timestamp_column)
|
|
|
|
| 36 |
df.to_csv(OUT_PATH, index=False)
|
| 37 |
|
| 38 |
if fig is not None:
|
| 39 |
+
yield (gr.update(visible=False), fig, OUT_PATH, gr.update(visible=False, value=""))
|
| 40 |
|
| 41 |
+
yield gr.update(visible=False),gr.update(visible=False), OUT_PATH, gr.update(visible=False, value="")
|
| 42 |
|
| 43 |
except Exception as e:
|
| 44 |
+
yield gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True, value=f"Error: {e}")
|
| 45 |
|
| 46 |
|
| 47 |
if os.path.exists(OUT_PATH):
|
|
|
|
| 62 |
and visualize the detected anomalies using the Chronos2 pipeline.
|
| 63 |
|
| 64 |
## Instructions
|
| 65 |
+
1. Click on the *Upload Time Series Data* button to upload your time series data in CSV format. The CSV file should have as columns only:
|
| 66 |
+
- **"timestamp":** the timestamp column of your data (e.g., "2023-01-01 00:00:00"). It is optional.
|
| 67 |
+
- **"values":** the columns containing the values of the time series data. They can be named as you wish. At least one column of values is required.
|
| 68 |
2. Answer the question about the timestamp in your data to help the model understand the temporal structure of your data.
|
| 69 |
- if present, you will need to specify the column name of the timestamp in your data.
|
| 70 |
- Otherwise, no need to do anything, just mark No.
|
| 71 |
+
3. Click on the *Detect Anomalies* button to run the Chronos2 pipeline and visualize the detected anomalies.
|
| 72 |
4. If the number of series is reasonably small, we will plot the original time series along with the detected anomalies.
|
| 73 |
5. We will provide a downloadable CSV file containing the original time series data along with an additional column indicating whether each point is an anomaly or not. We will label as 1 anomalies, as 0 normal points and as -1 the points for which we don't have a prediction because they are before the minimum length required by the model.
|
| 74 |
|
|
|
|
| 105 |
|
| 106 |
processing_msg = gr.Markdown("⏳ Processing file, please wait...", visible=False)
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
detect_button.click(
|
| 109 |
lambda file, timestamp_question, timestamp_column:
|
| 110 |
dataProcessing(
|
|
|
|
| 112 |
timestamp_column if timestamp_question == "Yes" else None
|
| 113 |
),
|
| 114 |
inputs=[file_input, timestamp_question, timestamp_column_input],
|
| 115 |
+
outputs=[processing_msg, plot_output, download_output, errorHandler]
|
| 116 |
)
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
demo.launch(share=True)
|