Spaces:
Running
Running
File size: 1,930 Bytes
21076a1 eb7c6a6 |
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 52 53 54 55 56 57 58 |
import requests
import xml.etree.ElementTree as ET
response = requests.get('https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495')
xml_str = response.content
root = ET.fromstring(xml_str)
# XML verileri burada kullanılabilir
import requests
import xml.etree.ElementTree as ET
import gradio as gr
# API'den stok verilerini çekmek için kullanacağımız fonksiyon
def get_stock_data():
response = requests.get('https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495')
xml_str = response.content
root = ET.fromstring(xml_str)
stock_dict = {}
for product in root.findall('product'):
name = product.find('name').text
stock = int(product.find('stock').text)
stock_dict[name] = stock
return stock_dict
# Chatbot fonksiyonu
def chatbot(input_text):
stock_dict = get_stock_data()
output_text = ""
for word in input_text.split():
if word.lower() in stock_dict.keys():
stock = stock_dict[word.lower()]
if stock == 0:
output_text += f"{word.capitalize()} stokta yok.\n"
elif stock < 2:
output_text += f"{word.capitalize()} stokta sınırlı sayıda bulunuyor.\n"
else:
output_text += f"{word.capitalize()} stokta bulunuyor.\n"
if not output_text:
output_text = "Ürün stoklarını sorgulamak için ürün ismini girin."
return output_text
# Gradio arayüzü
iface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
iface.launch()
def get_product_info(product_id):
for product in products:
if product['product_id'] == product_id:
name = product['name']
price = product['price']
color = product['color']
stock = product['stock']
return name, price, color, stock
return None, None, None, None
|