Spaces:
Running
Running
Fixed technical_specs extraction and updated dataset schema with technical_specs column
Browse files
app.py
CHANGED
|
@@ -288,27 +288,27 @@ def extract_technical_specs_from_text(text):
|
|
| 288 |
if not text:
|
| 289 |
return ""
|
| 290 |
tech_patterns = [
|
| 291 |
-
r'Kích thước[^::]*[::]?\s*(.+?)(?:
|
| 292 |
-
r'Chất liệu[^::]*[::]?\s*(.+?)(?:
|
| 293 |
-
r'
|
| 294 |
-
r'Chiều rộng[^::]*[::]?\s*(.+?)(?:\n|$)',
|
| 295 |
-
r'
|
| 296 |
-
r'
|
| 297 |
-
r'
|
| 298 |
-
r'
|
| 299 |
-
r'Màu sắc[^::]*[::]?\s*(.+?)(?:\n|$)',
|
| 300 |
-
r'Trong lượng[^::]*[::]?\s*(.+?)(?:\n|$)',
|
| 301 |
]
|
| 302 |
specs = []
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
| 309 |
return "\n".join(specs)[:500] if specs else ""
|
| 310 |
|
| 311 |
-
|
| 312 |
def _save_text_message_to_dataset(text, description, price, category, sender_id, sender_name, chat_id):
|
| 313 |
"""Save a text-only message to the main Zalo products dataset."""
|
| 314 |
try:
|
|
|
|
| 288 |
if not text:
|
| 289 |
return ""
|
| 290 |
tech_patterns = [
|
| 291 |
+
(r'Kích thước[^::]*[::]?\s*(.+?)(?:;|Chất liệu|Dòng sản phẩm|Bảo hành|Màu sắc|Khoang tủ|Chiều|$)', "Kích thước"),
|
| 292 |
+
(r'Chất liệu[^::]*[::]?\s*(.+?)(?:;|Kích thưỏi|Dòng sản phẩm|Bảo hành|Màu sắc|$)', "Chất liệu"),
|
| 293 |
+
(r'Dòng sản phẩm[^::]*[::]?\s*(.+?)(?:;|Kích thưỏi|Chất liệu|$)', "Dòng sản phẩm"),
|
| 294 |
+
(r'Chiều rộng tủ[^::]*[::]?\s*(.+?)(?:\n|$)', "Chiều rộng tủ"),
|
| 295 |
+
(r'Khoang tủ[^::]*[::]?\s*(.+?)(?:;|Kích thưỏi|Chất liệu|Chiều|$)', "Khoang tủ"),
|
| 296 |
+
(r'Bảo hành[^::]*[::]?\s*(.+?)(?:\n|$)', "Bảo hành"),
|
| 297 |
+
(r'Trọng lượng[^::]*[::]?\s*(.+?)(?:\n|$)', "Trọng lượng"),
|
| 298 |
+
(r'Màu sắc[^::]*[::]?\s*(.+?)(?:\n|$)', "Màu sắc"),
|
|
|
|
|
|
|
| 299 |
]
|
| 300 |
specs = []
|
| 301 |
+
seen = set()
|
| 302 |
+
for pattern, label in tech_patterns:
|
| 303 |
+
match = re.search(pattern, text, re.IGNORECASE | re.DOTALL)
|
| 304 |
+
if match:
|
| 305 |
+
value = match.group(1).strip()
|
| 306 |
+
if value and label.lower() not in seen:
|
| 307 |
+
value = value.rstrip(';').strip()
|
| 308 |
+
specs.append(f"{label}: {value}")
|
| 309 |
+
seen.add(label.lower())
|
| 310 |
return "\n".join(specs)[:500] if specs else ""
|
| 311 |
|
|
|
|
| 312 |
def _save_text_message_to_dataset(text, description, price, category, sender_id, sender_name, chat_id):
|
| 313 |
"""Save a text-only message to the main Zalo products dataset."""
|
| 314 |
try:
|