Download Stok from spg/chat: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/spg/chat/resolve/main/Stok
- Command line
-
hf download hf://spaces/spg/chat/Stok
-
curl -L -o Stok https://huggingface.co/spaces/spg/chat/resolve/main/Stok
1.87 kB
| 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) | |