Spaces:
Runtime error
Runtime error
Update interface.py
Browse files- interface.py +12 -2
interface.py
CHANGED
@@ -32,6 +32,7 @@ def create_sample_data():
|
|
32 |
def load_messages_from_file(file_obj):
|
33 |
"""
|
34 |
Read uploaded CSV or Excel file and convert to JSON string of message dicts.
|
|
|
35 |
"""
|
36 |
ext = os.path.splitext(file_obj.name)[1].lower()
|
37 |
try:
|
@@ -44,8 +45,17 @@ def load_messages_from_file(file_obj):
|
|
44 |
except Exception as e:
|
45 |
return {'error': f'Failed to read file: {e}'}
|
46 |
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
|
51 |
def analyze_uploaded_file(file_obj):
|
|
|
32 |
def load_messages_from_file(file_obj):
|
33 |
"""
|
34 |
Read uploaded CSV or Excel file and convert to JSON string of message dicts.
|
35 |
+
Handles pandas Timestamp conversion to strings.
|
36 |
"""
|
37 |
ext = os.path.splitext(file_obj.name)[1].lower()
|
38 |
try:
|
|
|
45 |
except Exception as e:
|
46 |
return {'error': f'Failed to read file: {e}'}
|
47 |
|
48 |
+
# Convert DataFrame to list of dicts
|
49 |
+
records = df.to_dict(orient='records')
|
50 |
+
# Serialize pandas Timestamps to ISO strings
|
51 |
+
for rec in records:
|
52 |
+
for key, val in rec.items():
|
53 |
+
if hasattr(val, 'isoformat'):
|
54 |
+
try:
|
55 |
+
rec[key] = val.isoformat()
|
56 |
+
except Exception:
|
57 |
+
rec[key] = str(val)
|
58 |
+
return json.dumps(records)
|
59 |
|
60 |
|
61 |
def analyze_uploaded_file(file_obj):
|