Update default time series
Browse files
app.py
CHANGED
@@ -33,10 +33,17 @@ model.eval()
|
|
33 |
|
34 |
def create_default_timeseries():
|
35 |
"""Create default time series with sudden increase"""
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
return df
|
41 |
|
42 |
def process_csv_file(csv_file):
|
@@ -131,12 +138,15 @@ def clear_csv():
|
|
131 |
return gr.LinePlot(value=pd.DataFrame()), message, gr.Dropdown()
|
132 |
|
133 |
|
134 |
-
def update_plot(csv_file, selected_column):
|
135 |
"""Update plot based on selected column"""
|
136 |
-
if csv_file is None or selected_column is None:
|
137 |
return gr.LinePlot(value=pd.DataFrame())
|
138 |
|
139 |
-
|
|
|
|
|
|
|
140 |
if df is None:
|
141 |
return gr.LinePlot(value=pd.DataFrame())
|
142 |
|
@@ -174,7 +184,7 @@ def initialize_interface():
|
|
174 |
label="Select a Column to Visualize"
|
175 |
)
|
176 |
|
177 |
-
message = "Using default time series
|
178 |
|
179 |
return plot, message, dropdown, True # Set use_default to True on initialization
|
180 |
|
@@ -333,7 +343,7 @@ with gr.Blocks(title="ChatTS Demo") as demo:
|
|
333 |
|
334 |
series_selector.change(
|
335 |
fn=update_plot,
|
336 |
-
inputs=[upload, series_selector],
|
337 |
outputs=[plot_out]
|
338 |
)
|
339 |
|
@@ -344,4 +354,4 @@ with gr.Blocks(title="ChatTS Demo") as demo:
|
|
344 |
)
|
345 |
|
346 |
if __name__ == '__main__':
|
347 |
-
demo.launch()
|
|
|
33 |
|
34 |
def create_default_timeseries():
|
35 |
"""Create default time series with sudden increase"""
|
36 |
+
x1 = np.arange(256)
|
37 |
+
x2 = np.arange(256)
|
38 |
+
ts1 = np.sin(x1 / 10) * 5.0
|
39 |
+
ts1[103:] -= 10.0
|
40 |
+
ts2 = x2 * 0.01
|
41 |
+
ts2[100] += 10.0
|
42 |
+
|
43 |
+
df = pd.DataFrame({
|
44 |
+
"TS1": ts1,
|
45 |
+
"TS2": ts2
|
46 |
+
})
|
47 |
return df
|
48 |
|
49 |
def process_csv_file(csv_file):
|
|
|
138 |
return gr.LinePlot(value=pd.DataFrame()), message, gr.Dropdown()
|
139 |
|
140 |
|
141 |
+
def update_plot(csv_file, selected_column, use_default_state):
|
142 |
"""Update plot based on selected column"""
|
143 |
+
if (csv_file is None and not use_default_state) or selected_column is None :
|
144 |
return gr.LinePlot(value=pd.DataFrame())
|
145 |
|
146 |
+
if csv_file is None and use_default_state:
|
147 |
+
df = create_default_timeseries()
|
148 |
+
else:
|
149 |
+
df, _ = process_csv_file(csv_file)
|
150 |
if df is None:
|
151 |
return gr.LinePlot(value=pd.DataFrame())
|
152 |
|
|
|
184 |
label="Select a Column to Visualize"
|
185 |
)
|
186 |
|
187 |
+
message = "Using default time series"
|
188 |
|
189 |
return plot, message, dropdown, True # Set use_default to True on initialization
|
190 |
|
|
|
343 |
|
344 |
series_selector.change(
|
345 |
fn=update_plot,
|
346 |
+
inputs=[upload, series_selector, use_default_state],
|
347 |
outputs=[plot_out]
|
348 |
)
|
349 |
|
|
|
354 |
)
|
355 |
|
356 |
if __name__ == '__main__':
|
357 |
+
demo.launch()
|