Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ import re
|
|
| 16 |
|
| 17 |
import logging
|
| 18 |
|
| 19 |
-
from pydantic import BaseModel, Field, ValidationError, RootModel
|
| 20 |
from typing import List, Optional
|
| 21 |
|
| 22 |
|
|
@@ -554,20 +554,29 @@ def deepseek_extract_price_list(price_list, save_json=False, json_name="price_li
|
|
| 554 |
计划来源: Optional[str] = ""
|
| 555 |
其他: Optional[dict] = Field(default_factory=dict, alias="其他")
|
| 556 |
|
| 557 |
-
|
| 558 |
# Ensures numbers remain as strings and aren't converted
|
| 559 |
-
coerce_numbers_to_str
|
| 560 |
# Allows numeric strings to be parsed into the model
|
| 561 |
-
arbitrary_types_allowed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
|
| 563 |
class PriceListModel(BaseModel):
|
| 564 |
items: List[PriceItem]
|
| 565 |
|
| 566 |
-
|
| 567 |
# Ensures numbers remain as strings and aren't converted
|
| 568 |
-
coerce_numbers_to_str
|
| 569 |
# Allows numeric strings to be parsed into the model
|
| 570 |
-
arbitrary_types_allowed
|
|
|
|
| 571 |
|
| 572 |
base_prompt = f"""你会接收到一个采购清单列表,请你提取以下字段并重新输出为一个结构化的 JSON 格式。
|
| 573 |
有时候第一行是表头,有时候是数据行,只输入数据行。
|
|
|
|
| 16 |
|
| 17 |
import logging
|
| 18 |
|
| 19 |
+
from pydantic import BaseModel, Field, ValidationError, RootModel, field_validator
|
| 20 |
from typing import List, Optional
|
| 21 |
|
| 22 |
|
|
|
|
| 554 |
计划来源: Optional[str] = ""
|
| 555 |
其他: Optional[dict] = Field(default_factory=dict, alias="其他")
|
| 556 |
|
| 557 |
+
model_config = {
|
| 558 |
# Ensures numbers remain as strings and aren't converted
|
| 559 |
+
"coerce_numbers_to_str": True,
|
| 560 |
# Allows numeric strings to be parsed into the model
|
| 561 |
+
"arbitrary_types_allowed": True
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
@field_validator('其他', mode='before')
|
| 565 |
+
def convert_empty_list_to_dict(cls, v):
|
| 566 |
+
# Convert empty list to empty dict
|
| 567 |
+
if isinstance(v, list) and len(v) == 0:
|
| 568 |
+
return {}
|
| 569 |
+
return v
|
| 570 |
|
| 571 |
class PriceListModel(BaseModel):
|
| 572 |
items: List[PriceItem]
|
| 573 |
|
| 574 |
+
model_config = {
|
| 575 |
# Ensures numbers remain as strings and aren't converted
|
| 576 |
+
"coerce_numbers_to_str": True,
|
| 577 |
# Allows numeric strings to be parsed into the model
|
| 578 |
+
"arbitrary_types_allowed": True
|
| 579 |
+
}
|
| 580 |
|
| 581 |
base_prompt = f"""你会接收到一个采购清单列表,请你提取以下字段并重新输出为一个结构化的 JSON 格式。
|
| 582 |
有时候第一行是表头,有时候是数据行,只输入数据行。
|