SamiKoen commited on
Commit
365f6e4
1 Parent(s): a066b25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -102,4 +102,62 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
102
  inputs.submit( predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter],) #openai_api_key
103
  inputs.submit(reset_textbox, [], [inputs])
104
 
105
- demo.queue(max_size=20, concurrency_count=20).launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  inputs.submit( predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter],) #openai_api_key
103
  inputs.submit(reset_textbox, [], [inputs])
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
+ response = requests.get('https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495')
111
+ xml_str = response.content
112
+
113
+ root = ET.fromstring(xml_str)
114
+
115
+ # XML verileri burada kullanılabilir
116
+
117
+ import requests
118
+ import xml.etree.ElementTree as ET
119
+ import gradio as gr
120
+
121
+ # API'den stok verilerini çekmek için kullanacağımız fonksiyon
122
+ def get_stock_data():
123
+ response = requests.get('https://bizimhesap.com/api/product/getproductsasxml?apikey=6F4BAF303FA240608A39653824B6C495')
124
+ xml_str = response.content
125
+ root = ET.fromstring(xml_str)
126
+ stock_dict = {}
127
+ for product in root.findall('product'):
128
+ name = product.find('name').text
129
+ stock = int(product.find('stock').text)
130
+ stock_dict[name] = stock
131
+ return stock_dict
132
+
133
+ # Chatbot fonksiyonu
134
+ def chatbot(input_text):
135
+ stock_dict = get_stock_data()
136
+ output_text = ""
137
+ for word in input_text.split():
138
+ if word.lower() in stock_dict.keys():
139
+ stock = stock_dict[word.lower()]
140
+ if stock == 0:
141
+ output_text += f"{word.capitalize()} stokta yok.\n"
142
+ elif stock < 2:
143
+ output_text += f"{word.capitalize()} stokta sınırlı sayıda bulunuyor.\n"
144
+ else:
145
+ output_text += f"{word.capitalize()} stokta bulunuyor.\n"
146
+ if not output_text:
147
+ output_text = "Ürün stoklarını sorgulamak için ürün ismini girin."
148
+ return output_text
149
+
150
+ # Gradio arayüzü
151
+ iface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
152
+ iface.launch()
153
+
154
+ def get_product_info(product_id):
155
+ for product in products:
156
+ if product['product_id'] == product_id:
157
+ name = product['name']
158
+ price = product['price']
159
+ color = product['color']
160
+ stock = product['stock']
161
+ return name, price, color, stock
162
+ return None, None, None, None
163
+