Update Stok
Browse files
Stok
CHANGED
|
@@ -1,57 +1,50 @@
|
|
| 1 |
import requests
|
| 2 |
import xml.etree.ElementTree as ET
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
#
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
response = requests.get('https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495')
|
| 18 |
-
xml_str = response.content
|
| 19 |
-
root = ET.fromstring(xml_str)
|
| 20 |
-
stock_dict = {}
|
| 21 |
-
for product in root.findall('product'):
|
| 22 |
-
name = product.find('name').text
|
| 23 |
-
stock = int(product.find('stock').text)
|
| 24 |
-
stock_dict[name] = stock
|
| 25 |
-
return stock_dict
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
output_text += f"{word.capitalize()} stokta yok.\n"
|
| 36 |
-
elif stock < 2:
|
| 37 |
-
output_text += f"{word.capitalize()} stokta sınırlı sayıda bulunuyor.\n"
|
| 38 |
else:
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
#
|
| 45 |
-
iface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
|
| 46 |
-
iface.launch()
|
| 47 |
-
|
| 48 |
-
def get_product_info(product_id):
|
| 49 |
for product in products:
|
| 50 |
-
if product
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
import xml.etree.ElementTree as ET
|
| 3 |
+
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Hugging Face pipeline'ını yükle
|
| 6 |
+
nlp = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B')
|
| 7 |
|
| 8 |
+
# API url'si
|
| 9 |
+
url = 'https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495'
|
| 10 |
|
| 11 |
+
# Verileri al
|
| 12 |
+
response = requests.get(url)
|
| 13 |
+
xml_data = response.content
|
| 14 |
|
| 15 |
+
# XML verilerini ayrıştır
|
| 16 |
+
root = ET.fromstring(xml_data)
|
| 17 |
+
products = root.findall('urunler/urun')
|
| 18 |
|
| 19 |
+
# Chatbot'a girdi al
|
| 20 |
+
input_text = input("Merhaba, ne yapabilirim? ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Girdiye göre yanıt üret
|
| 23 |
+
if 'stok' in input_text and ('durum' in input_text or 'seviye' in input_text):
|
| 24 |
+
# Eğer kullanıcı stok durumunu sorduysa
|
| 25 |
+
for product in products:
|
| 26 |
+
if product.find('urun_ad').text.lower() in input_text.lower():
|
| 27 |
+
stok = int(product.find('stok').text)
|
| 28 |
+
if stok > 0:
|
| 29 |
+
response_text = f"{product.find('urun_ad').text} ürününden {stok} adet mevcut."
|
|
|
|
|
|
|
|
|
|
| 30 |
else:
|
| 31 |
+
response_text = f"{product.find('urun_ad').text} ürünü stoklarda yok."
|
| 32 |
+
break
|
| 33 |
+
else:
|
| 34 |
+
response_text = "Aradığınız ürün stoklarda yok."
|
| 35 |
+
elif 'fiyat' in input_text:
|
| 36 |
+
# Eğer kullanıcı fiyat bilgisi istiyorsa
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
for product in products:
|
| 38 |
+
if product.find('urun_ad').text.lower() in input_text.lower():
|
| 39 |
+
price = float(product.find('satis_fiyat').text)
|
| 40 |
+
response_text = f"{product.find('urun_ad').text} ürününün fiyatı {price:.2f} TL."
|
| 41 |
+
break
|
| 42 |
+
else:
|
| 43 |
+
response_text = "Aradığınız ürün fiyatı hakkında bilgi verilemedi."
|
| 44 |
+
else:
|
| 45 |
+
# Girdiye göre otomatik bir yanıt üret
|
| 46 |
+
generated_text = nlp(input_text, max_length=50, do_sample=True, temperature=0.7)
|
| 47 |
+
response_text = generated_text[0]['generated_text'].strip()
|
| 48 |
+
|
| 49 |
+
# Yanıtı yazdır
|
| 50 |
+
print(response_text)
|