Backup geri yüklendi - iki aşamalı arama iptal
Browse files
app.py
CHANGED
@@ -503,58 +503,16 @@ def chatbot_fn(user_message, history, image=None):
|
|
503 |
if product_words:
|
504 |
product_name = ' '.join(product_words)
|
505 |
|
506 |
-
#
|
507 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
stock_info = get_realtime_stock(product_name)
|
509 |
|
510 |
-
# 2. Aşama: Bulamazsa XML'de benzer ürün bul ve onunla tekrar dene
|
511 |
-
if not stock_info:
|
512 |
-
print(f"API'de '{product_name}' bulunamadı, XML'de aranıyor...")
|
513 |
-
|
514 |
-
# Beden kontrolü - tek harfli kelimeler beden olabilir
|
515 |
-
size_words = ['s', 'm', 'l', 'xl', 'xxl', 'xs']
|
516 |
-
has_size = False
|
517 |
-
size_requested = None
|
518 |
-
|
519 |
-
for word in product_words:
|
520 |
-
if word.lower() in size_words:
|
521 |
-
has_size = True
|
522 |
-
size_requested = word.upper()
|
523 |
-
break
|
524 |
-
|
525 |
-
# XML'deki products listesinde ara
|
526 |
-
found_product = None
|
527 |
-
for _, product_info, full_name in products:
|
528 |
-
full_name_lower = full_name.lower()
|
529 |
-
|
530 |
-
# Beden belirtilmişse
|
531 |
-
if has_size and size_requested:
|
532 |
-
# Beden hariç diğer kelimeleri kontrol et
|
533 |
-
other_words = [w for w in product_words if w.lower() not in size_words]
|
534 |
-
# Diğer kelimeler ürün adında var mı?
|
535 |
-
if all(word in full_name_lower for word in other_words):
|
536 |
-
# Ve istenen beden tam olarak eşleşiyor mu? (M-KREM veya M - formatında)
|
537 |
-
if f' {size_requested} -' in full_name or f' {size_requested}-' in full_name:
|
538 |
-
found_product = full_name
|
539 |
-
print(f"XML'de beden eşleşmesi bulundu: {found_product}")
|
540 |
-
break
|
541 |
-
else:
|
542 |
-
# Beden belirtilmemişse normal arama
|
543 |
-
if all(word in full_name_lower for word in product_words):
|
544 |
-
found_product = full_name
|
545 |
-
print(f"XML'de eşleşen ürün bulundu: {found_product}")
|
546 |
-
break
|
547 |
-
|
548 |
-
# Bulunan ürün adıyla API'yi tekrar çağır
|
549 |
-
if found_product:
|
550 |
-
# XML'deki ürün adını temizle (sadece ana ürün adını al)
|
551 |
-
# Örnek: "FX SPORT AL 3 L - KREM" -> "FX SPORT AL 3"
|
552 |
-
clean_name = found_product.split(' - ')[0] # Renk bilgisini çıkar
|
553 |
-
clean_name = ' '.join(clean_name.split()[:4]) # İlk 4 kelimeyi al (model adı genelde 4 kelime)
|
554 |
-
|
555 |
-
print(f"Temizlenmiş ürün adıyla tekrar deneniyor: {clean_name}")
|
556 |
-
stock_info = get_realtime_stock(clean_name.lower())
|
557 |
-
|
558 |
if stock_info:
|
559 |
# Stok bilgisini sistem mesajına ekle
|
560 |
system_messages.append({
|
|
|
503 |
if product_words:
|
504 |
product_name = ' '.join(product_words)
|
505 |
|
506 |
+
# FX Sport AL 3 gibi özel ürün isimlerini düzelt
|
507 |
+
# "fx sport 3 al" -> "fx sport al 3"
|
508 |
+
if 'fx sport' in product_name and '3' in product_name:
|
509 |
+
if 'al' in product_name:
|
510 |
+
# Kelime sırasını düzelt
|
511 |
+
product_name = 'fx sport al 3'
|
512 |
+
elif 'carbon' in product_name:
|
513 |
+
product_name = 'fx sport carbon'
|
514 |
stock_info = get_realtime_stock(product_name)
|
515 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
if stock_info:
|
517 |
# Stok bilgisini sistem mesajına ekle
|
518 |
system_messages.append({
|