pavanmutha commited on
Commit
be74d22
·
verified ·
1 Parent(s): 19a2f77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -13,7 +13,6 @@ from sklearn.ensemble import RandomForestClassifier
13
  from sklearn.model_selection import train_test_split, cross_val_score
14
  from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
15
  from sklearn.preprocessing import LabelEncoder
16
- from smolagents.types import AgentText
17
 
18
  # Authenticate with Hugging Face
19
  hf_token = os.getenv("HF_TOKEN")
@@ -86,21 +85,17 @@ def run_agent(_):
86
  additional_args={"source_file": temp_file.name}
87
  )
88
 
89
- # Convert AgentText object to string and parse it
90
- if isinstance(result, AgentText):
91
- import json
92
- result_str = result.text.strip()
93
-
94
- try:
95
- result_dict = json.loads(result_str)
96
- except json.JSONDecodeError:
97
- return f"Error decoding agent response: {result_str}", []
98
 
99
  insights = result_dict.get("insights", "No insights generated.")
100
  image_paths = result_dict.get("figures", [])
101
  return insights, image_paths
102
- else:
103
- return "Unexpected result type from agent", []
 
104
 
105
 
106
 
 
13
  from sklearn.model_selection import train_test_split, cross_val_score
14
  from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
15
  from sklearn.preprocessing import LabelEncoder
 
16
 
17
  # Authenticate with Hugging Face
18
  hf_token = os.getenv("HF_TOKEN")
 
85
  additional_args={"source_file": temp_file.name}
86
  )
87
 
88
+ # If the result is text, attempt to parse it as JSON
89
+ try:
90
+ result_str = result.strip()
91
+ result_dict = json.loads(result_str)
 
 
 
 
 
92
 
93
  insights = result_dict.get("insights", "No insights generated.")
94
  image_paths = result_dict.get("figures", [])
95
  return insights, image_paths
96
+ except Exception as e:
97
+ return f"Error parsing agent response: {e}", []
98
+
99
 
100
 
101