SamiKoen commited on
Commit
eb7c6a6
·
1 Parent(s): 21076a1

Update Stok.api

Browse files
Files changed (1) hide show
  1. Stok.api +48 -0
Stok.api CHANGED
@@ -7,3 +7,51 @@ xml_str = response.content
7
  root = ET.fromstring(xml_str)
8
 
9
  # XML verileri burada kullanılabilir
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+