File size: 1,865 Bytes
16314be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests
import xml.etree.ElementTree as ET
from transformers import pipeline

# Hugging Face pipeline'ını yükle
nlp = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B')

# API url'si
url = 'https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495'

# Verileri al
response = requests.get(url)
xml_data = response.content

# XML verilerini ayrıştır
root = ET.fromstring(xml_data)
products = root.findall('urunler/urun')

# Chatbot'a girdi al
input_text = input("Merhaba, ne yapabilirim? ")

# Girdiye göre yanıt üret
if 'stok' in input_text and ('durum' in input_text or 'seviye' in input_text):
    # Eğer kullanıcı stok durumunu sorduysa
    for product in products:
        if product.find('urun_ad').text.lower() in input_text.lower():
            stok = int(product.find('stok').text)
            if stok > 0:
                response_text = f"{product.find('urun_ad').text} ürününden {stok} adet mevcut."
            else:
                response_text = f"{product.find('urun_ad').text} ürünü stoklarda yok."
            break
    else:
        response_text = "Aradığınız ürün stoklarda yok."
elif 'fiyat' in input_text:
    # Eğer kullanıcı fiyat bilgisi istiyorsa
    for product in products:
        if product.find('urun_ad').text.lower() in input_text.lower():
            price = float(product.find('satis_fiyat').text)
            response_text = f"{product.find('urun_ad').text} ürününün fiyatı {price:.2f} TL."
            break
    else:
        response_text = "Aradığınız ürün fiyatı hakkında bilgi verilemedi."
else:
    # Girdiye göre otomatik bir yanıt üret
    generated_text = nlp(input_text, max_length=50, do_sample=True, temperature=0.7)
    response_text = generated_text[0]['generated_text'].strip()

# Yanıtı yazdır
print(response_text)