SamiKoen commited on
Commit
162fac8
1 Parent(s): 0ca9ed5

Update Stok

Browse files
Files changed (1) hide show
  1. Stok +40 -47
Stok CHANGED
@@ -1,57 +1,50 @@
1
  import requests
2
  import xml.etree.ElementTree as ET
 
3
 
4
- response = requests.get('https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495')
5
- xml_str = response.content
6
 
7
- root = ET.fromstring(xml_str)
 
8
 
9
- # XML verileri burada kullanılabilir
 
 
10
 
11
- import requests
12
- import xml.etree.ElementTree as ET
13
- import gradio as gr
14
 
15
- # API'den stok verilerini çekmek için kullanacağımız fonksiyon
16
- def get_stock_data():
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
- # Chatbot fonksiyonu
28
- def chatbot(input_text):
29
- stock_dict = get_stock_data()
30
- output_text = ""
31
- for word in input_text.split():
32
- if word.lower() in stock_dict.keys():
33
- stock = stock_dict[word.lower()]
34
- if stock == 0:
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
- output_text += f"{word.capitalize()} stokta bulunuyor.\n"
40
- if not output_text:
41
- output_text = "Ürün stoklarını sorgulamak için ürün ismini girin."
42
- return output_text
43
-
44
- # Gradio arayüzü
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['product_id'] == product_id:
51
- name = product['name']
52
- price = product['price']
53
- color = product['color']
54
- stock = product['stock']
55
- return name, price, color, stock
56
- return None, None, None, None
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)