Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -276,12 +276,43 @@ def create_visualizations(analyst_output):
|
|
276 |
def display_table(analyst_output):
|
277 |
table_data = []
|
278 |
validated_data = validate_analyst_output(analyst_output)
|
|
|
279 |
if validated_data:
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
return table_data
|
284 |
|
|
|
285 |
def parse_analyst_output(raw_output):
|
286 |
structured_data = []
|
287 |
current_category = None
|
|
|
276 |
def display_table(analyst_output):
|
277 |
table_data = []
|
278 |
validated_data = validate_analyst_output(analyst_output)
|
279 |
+
|
280 |
if validated_data:
|
281 |
+
for item in validated_data:
|
282 |
+
category = item["Category"]
|
283 |
+
values = item["Values"]
|
284 |
+
|
285 |
+
try:
|
286 |
+
# Dictionary → Structured Table
|
287 |
+
if isinstance(values, dict):
|
288 |
+
df = pd.DataFrame(list(values.items()), columns=["Label", "Count"])
|
289 |
+
st.subheader(f"{category} (Table View)")
|
290 |
+
st.dataframe(df)
|
291 |
+
table_data.extend(df.to_dict(orient="records"))
|
292 |
+
|
293 |
+
# List → Simple List Table
|
294 |
+
elif isinstance(values, list):
|
295 |
+
df = pd.DataFrame(values, columns=["Items"])
|
296 |
+
st.subheader(f"{category} (List View)")
|
297 |
+
st.dataframe(df)
|
298 |
+
table_data.extend(df.to_dict(orient="records"))
|
299 |
+
|
300 |
+
# String → Text Table
|
301 |
+
elif isinstance(values, str):
|
302 |
+
st.subheader(f"{category} (Summary)")
|
303 |
+
st.table(pd.DataFrame({"Insights": [values]}))
|
304 |
+
table_data.append({"Category": category, "Values": values})
|
305 |
+
|
306 |
+
else:
|
307 |
+
st.warning(f"Unsupported data format for category: {category}")
|
308 |
+
|
309 |
+
except Exception as e:
|
310 |
+
logging.error(f"Error displaying {category} as table: {e}")
|
311 |
+
st.error(f"Failed to display {category} as a table.")
|
312 |
+
|
313 |
return table_data
|
314 |
|
315 |
+
|
316 |
def parse_analyst_output(raw_output):
|
317 |
structured_data = []
|
318 |
current_category = None
|