Debug
Browse files
app.py
CHANGED
@@ -89,16 +89,12 @@ def process_csv_file(csv_file):
|
|
89 |
except Exception as e:
|
90 |
return None, f"Error processing file: {str(e)}"
|
91 |
|
92 |
-
def get_current_data(csv_file):
|
93 |
-
"""Get current data (either uploaded CSV or default)"""
|
94 |
-
if csv_file is None:
|
95 |
-
return create_default_timeseries(), "Using default time series with sudden increase at step 100"
|
96 |
-
else:
|
97 |
-
return process_csv_file(csv_file)
|
98 |
-
|
99 |
def preview_csv(csv_file):
|
100 |
"""Preview uploaded CSV file immediately"""
|
101 |
-
|
|
|
|
|
|
|
102 |
|
103 |
if df is None:
|
104 |
return gr.LinePlot(value=pd.DataFrame()), message, gr.Dropdown()
|
@@ -130,10 +126,10 @@ def preview_csv(csv_file):
|
|
130 |
|
131 |
def update_plot(csv_file, selected_column):
|
132 |
"""Update plot based on selected column"""
|
133 |
-
if selected_column is None:
|
134 |
return gr.LinePlot(value=pd.DataFrame())
|
135 |
|
136 |
-
df, _ =
|
137 |
if df is None:
|
138 |
return gr.LinePlot(value=pd.DataFrame())
|
139 |
|
@@ -183,13 +179,18 @@ def infer_chatts_stream(prompt: str, csv_file):
|
|
183 |
Streaming version of ChatTS inference
|
184 |
"""
|
185 |
print("Start inferring!!!")
|
186 |
-
|
187 |
if not prompt.strip():
|
188 |
yield "Please enter a prompt"
|
189 |
return
|
190 |
|
191 |
-
#
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
193 |
if df is None:
|
194 |
yield f"Error: {error_msg}"
|
195 |
return
|
@@ -215,6 +216,8 @@ def infer_chatts_stream(prompt: str, csv_file):
|
|
215 |
prefix += f"The {name} is of length {len(arr)}: <ts><ts/>\n"
|
216 |
full_prompt = prefix + formatted_prompt
|
217 |
|
|
|
|
|
218 |
# Encode inputs
|
219 |
inputs = processor(
|
220 |
text=[full_prompt],
|
@@ -260,7 +263,7 @@ with gr.Blocks(title="ChatTS Demo") as demo:
|
|
260 |
)
|
261 |
|
262 |
prompt_input = gr.Textbox(
|
263 |
-
lines=
|
264 |
placeholder="Enter your analysis prompt here...",
|
265 |
label="Analysis Prompt",
|
266 |
value="Please analyze this time series and provide insights about the trends, seasonality, and local fluctuations."
|
|
|
89 |
except Exception as e:
|
90 |
return None, f"Error processing file: {str(e)}"
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
def preview_csv(csv_file):
|
93 |
"""Preview uploaded CSV file immediately"""
|
94 |
+
if csv_file is None:
|
95 |
+
return gr.LinePlot(value=pd.DataFrame()), "Please upload a CSV file first", gr.Dropdown()
|
96 |
+
|
97 |
+
df, message = process_csv_file(csv_file)
|
98 |
|
99 |
if df is None:
|
100 |
return gr.LinePlot(value=pd.DataFrame()), message, gr.Dropdown()
|
|
|
126 |
|
127 |
def update_plot(csv_file, selected_column):
|
128 |
"""Update plot based on selected column"""
|
129 |
+
if csv_file is None or selected_column is None:
|
130 |
return gr.LinePlot(value=pd.DataFrame())
|
131 |
|
132 |
+
df, _ = process_csv_file(csv_file)
|
133 |
if df is None:
|
134 |
return gr.LinePlot(value=pd.DataFrame())
|
135 |
|
|
|
179 |
Streaming version of ChatTS inference
|
180 |
"""
|
181 |
print("Start inferring!!!")
|
182 |
+
|
183 |
if not prompt.strip():
|
184 |
yield "Please enter a prompt"
|
185 |
return
|
186 |
|
187 |
+
# Use default if no file uploaded, otherwise process CSV
|
188 |
+
if csv_file is None:
|
189 |
+
df = create_default_timeseries()
|
190 |
+
error_msg = None
|
191 |
+
else:
|
192 |
+
df, error_msg = process_csv_file(csv_file)
|
193 |
+
|
194 |
if df is None:
|
195 |
yield f"Error: {error_msg}"
|
196 |
return
|
|
|
216 |
prefix += f"The {name} is of length {len(arr)}: <ts><ts/>\n"
|
217 |
full_prompt = prefix + formatted_prompt
|
218 |
|
219 |
+
print(f"[debug] {full_prompt=}, {len(ts_list)=}, {[len(item) for item in ts_list]=}")
|
220 |
+
|
221 |
# Encode inputs
|
222 |
inputs = processor(
|
223 |
text=[full_prompt],
|
|
|
263 |
)
|
264 |
|
265 |
prompt_input = gr.Textbox(
|
266 |
+
lines=6,
|
267 |
placeholder="Enter your analysis prompt here...",
|
268 |
label="Analysis Prompt",
|
269 |
value="Please analyze this time series and provide insights about the trends, seasonality, and local fluctuations."
|