SamiKoen commited on
Commit
02cb3a2
·
1 Parent(s): a7eb3c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -30
app.py CHANGED
@@ -104,9 +104,32 @@ 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 requests
108
  import xml.etree.ElementTree as ET
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  def get_product_info(product_name):
111
  api_key = "6F4BAF303FA240608A39653824B6C495"
112
  url = f"https://bizimhesap.com/api/product/getproductsasxml?apikey={api_key}"
@@ -134,37 +157,13 @@ def get_product_info(product_name):
134
  product_info["frame_size"] = variant[frame_size_start:].strip()
135
  return product_info
136
 
137
- # Gradio UI
138
- import gradio as gr
139
-
140
- def answer_question(question):
141
- if "stok" in question.lower():
142
- product_name = question.lower().replace("stokta", "").replace("stok", "").replace("miktar", "").strip()
143
- product_info = get_product_info(product_name)
144
- if not product_info:
145
- return f"{product_name.title()} ürünü maalesef stoklarımızda bulunmamaktadır."
146
- else:
147
- stock = product_info["stock"]
148
- return f"{product_info['name'].title()} ürününden {stock} adet stoklarımızda mevcuttur."
149
- elif "fiyat" in question.lower():
150
- product_name = question.lower().replace("fiyatı", "").replace("fiyat", "").strip()
151
- product_info = get_product_info(product_name)
152
- if not product_info:
153
- return f"{product_name.title()} ürünü maalesef stoklarımızda bulunmamaktadır."
154
- else:
155
- price = product_info["price"]
156
- currency = product_info["currency"]
157
- return f"{product_info['name'].title()} ürününün fiyatı {price} {currency}'dir."
158
- else:
159
- return "Maalesef anlayamadım. Lütfen sorunuzu tekrar sorun."
160
-
161
  iface = gr.Interface(
162
- fn=answer_question,
163
- inputs="text",
164
- outputs="text",
165
- title="BizimHesap Chatbot",
166
- description="Ürün stok ve fiyat sorguları için kullanabilirsiniz.",
167
- theme="huggingface"
168
  )
169
 
170
  iface.launch()
 
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}"
 
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()