Spaces:
Running
Running
Update eb_agent_module.py
Browse files- eb_agent_module.py +25 -25
eb_agent_module.py
CHANGED
@@ -594,31 +594,31 @@ class EmployerBrandingAgent:
|
|
594 |
dfs = list(self.pandas_dfs.values())
|
595 |
pandas_response = pai.chat(query, *dfs)
|
596 |
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
|
623 |
except Exception as e:
|
624 |
logging.error(f"Error in PandasAI processing: {e}", exc_info=True)
|
|
|
594 |
dfs = list(self.pandas_dfs.values())
|
595 |
pandas_response = pai.chat(query, *dfs)
|
596 |
|
597 |
+
# Handle different response types (text, charts, etc.)
|
598 |
+
response_text = ""
|
599 |
+
chart_info = ""
|
600 |
+
|
601 |
+
# Check if a chart was generated
|
602 |
+
import os
|
603 |
+
charts_dir = "./charts"
|
604 |
+
if os.path.exists(charts_dir):
|
605 |
+
chart_files = [f for f in os.listdir(charts_dir) if f.endswith(('.png', '.jpg', '.jpeg', '.svg'))]
|
606 |
+
if chart_files:
|
607 |
+
# Get the most recent chart file
|
608 |
+
chart_files.sort(key=lambda x: os.path.getmtime(os.path.join(charts_dir, x)), reverse=True)
|
609 |
+
latest_chart = chart_files[0]
|
610 |
+
chart_path = os.path.join(charts_dir, latest_chart)
|
611 |
+
chart_info = f"\n\n📊 **Chart Generated**: {latest_chart}\nChart saved at: {chart_path}"
|
612 |
+
logging.info(f"Chart generated: {chart_path}")
|
613 |
+
|
614 |
+
# Combine text response with chart info
|
615 |
+
if pandas_response and str(pandas_response).strip():
|
616 |
+
response_text = str(pandas_response).strip()
|
617 |
+
else:
|
618 |
+
response_text = "Analysis completed"
|
619 |
+
|
620 |
+
final_response = response_text + chart_info
|
621 |
+
return final_response, True
|
622 |
|
623 |
except Exception as e:
|
624 |
logging.error(f"Error in PandasAI processing: {e}", exc_info=True)
|