Update app.py
Browse files
app.py
CHANGED
@@ -104,66 +104,3 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
104 |
|
105 |
demo.queue(max_size=20, concurrency_count=20).launch(debug=True)
|
106 |
|
107 |
-
import gradio as gr
|
108 |
-
import requests
|
109 |
-
import xml.etree.ElementTree as ET
|
110 |
-
|
111 |
-
def predict(input_text):
|
112 |
-
if "stok" in input_text.lower():
|
113 |
-
product_name = input_text.lower().replace("stokta", "").replace("stok", "").replace("miktar", "").strip()
|
114 |
-
product_info = get_product_info(product_name)
|
115 |
-
if not product_info:
|
116 |
-
return f"{product_name.title()} ürünü maalesef stoklarımızda bulunmamaktadır."
|
117 |
-
else:
|
118 |
-
stock = product_info["stock"]
|
119 |
-
return f"{product_info['name'].title()} ürününden {stock} adet stoklarımızda mevcuttur."
|
120 |
-
elif "fiyat" in input_text.lower():
|
121 |
-
product_name = input_text.lower().replace("fiyatı", "").replace("fiyat", "").strip()
|
122 |
-
product_info = get_product_info(product_name)
|
123 |
-
if not product_info:
|
124 |
-
return f"{product_name.title()} ürünü maalesef stoklarımızda bulunmamaktadır."
|
125 |
-
else:
|
126 |
-
price = product_info["price"]
|
127 |
-
currency = product_info["currency"]
|
128 |
-
return f"{product_info['name'].title()} ürününün fiyatı {price} {currency}'dir."
|
129 |
-
else:
|
130 |
-
return "Maalesef anlayamadım. Lütfen sorunuzu tekrar sorun."
|
131 |
-
|
132 |
-
|
133 |
-
def get_product_info(product_name):
|
134 |
-
api_key = "6F4BAF303FA240608A39653824B6C495"
|
135 |
-
url = f"https://bizimhesap.com/api/product/getproductsasxml?apikey={api_key}"
|
136 |
-
response = requests.get(url)
|
137 |
-
root = ET.fromstring(response.content)
|
138 |
-
product_info = {}
|
139 |
-
for product in root.findall("./urunler/urun"):
|
140 |
-
name = product.find("./urun_ad").text.strip()
|
141 |
-
if product_name.lower() in name.lower():
|
142 |
-
product_info["name"] = name
|
143 |
-
product_info["code"] = product.find("./stok_kod").text.strip()
|
144 |
-
product_info["stock"] = int(product.find("./stok").text)
|
145 |
-
product_info["price"] = float(product.find("./satis_fiyat").text.replace(',', '.'))
|
146 |
-
product_info["currency"] = product.find("./para_birim").text.strip()
|
147 |
-
product_info["detail"] = product.find("./detay").text.strip()
|
148 |
-
product_info["category"] = product.find("./kat_yolu").text.strip()
|
149 |
-
product_info["image_url"] = product.find("./resim").text.strip()
|
150 |
-
variant = product.find("./varyant").text.strip()
|
151 |
-
if "renk" in variant.lower():
|
152 |
-
color_start = variant.find("(") + 1
|
153 |
-
color_end = variant.find(")", color_start)
|
154 |
-
product_info["color"] = variant[color_start:color_end]
|
155 |
-
if "kadro" in variant.lower():
|
156 |
-
frame_size_start = variant.find(":") + 1
|
157 |
-
product_info["frame_size"] = variant[frame_size_start:].strip()
|
158 |
-
return product_info
|
159 |
-
|
160 |
-
iface = gr.Interface(
|
161 |
-
predict,
|
162 |
-
"textbox",
|
163 |
-
"text",
|
164 |
-
examples=[["Bisiklet fiyatı nedir?"], ["Telefon stefon stokta var mı?"], ["Kırmızı bisiklet kadrosu hangi boyutlarda mevcut?"]],
|
165 |
-
title="Bizim Hesap Chatbot",
|
166 |
-
description="Bu chatbot ile Bizim Hesap mağazasındaki ürünlerin stok bilgileri ve fiyatları hakkında bilgi alabilirsiniz."
|
167 |
-
)
|
168 |
-
|
169 |
-
iface.launch()
|
|
|
104 |
|
105 |
demo.queue(max_size=20, concurrency_count=20).launch(debug=True)
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|