ChatGPT444 / Stok
SamiKoen's picture
Rename Stok.api to Stok
1dca050
raw
history blame
1.93 kB
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