| import requests |
| import xml.etree.ElementTree as ET |
| from transformers import pipeline |
|
|
| |
| nlp = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B') |
|
|
| |
| url = 'https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495' |
|
|
| |
| response = requests.get(url) |
| xml_data = response.content |
|
|
| |
| root = ET.fromstring(xml_data) |
| products = root.findall('urunler/urun') |
|
|
| |
| input_text = input("Merhaba, ne yapabilirim? ") |
|
|
| |
| if 'stok' in input_text and ('durum' in input_text or 'seviye' in input_text): |
| |
| 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: |
| |
| 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: |
| |
| generated_text = nlp(input_text, max_length=50, do_sample=True, temperature=0.7) |
| response_text = generated_text[0]['generated_text'].strip() |
|
|
| |
| print(response_text) |
|
|