Spaces:
Runtime error
Runtime error
Update code.py
Browse files
code.py
CHANGED
|
@@ -505,7 +505,13 @@ def structured_output(texts, api_key):
|
|
| 505 |
# Transform items data to dataframe
|
| 506 |
items_df = pd.DataFrame(data.get('items', []))
|
| 507 |
|
| 508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
items_df[column] = pd.to_numeric(items_df[column], errors='coerce')
|
| 510 |
|
| 511 |
items_df = ensure_category(items_df)
|
|
|
|
| 505 |
# Transform items data to dataframe
|
| 506 |
items_df = pd.DataFrame(data.get('items', []))
|
| 507 |
|
| 508 |
+
# Fill 'unit' column with 1 if it is missing
|
| 509 |
+
if 'unit' not in items_df.columns:
|
| 510 |
+
items_df['unit'] = 1
|
| 511 |
+
else:
|
| 512 |
+
items_df['unit'] = pd.to_numeric(items_df['unit'], errors='coerce').fillna(1)
|
| 513 |
+
|
| 514 |
+
for column in ['price', 'amount']:
|
| 515 |
items_df[column] = pd.to_numeric(items_df[column], errors='coerce')
|
| 516 |
|
| 517 |
items_df = ensure_category(items_df)
|