Update app.py
Browse files
app.py
CHANGED
@@ -34,21 +34,28 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
34 |
print(f"system message is ^^ {system_msg}")
|
35 |
|
36 |
multi_turn_message = [
|
37 |
-
{"role": "system", "content": "Bir önceki sohbeti unut. Vereceğin ürün bilgisi, bu bilginin içinde yan yana
|
38 |
{"role": "system", "content": "Dağ bisikletleri modelleri: Marlin, Roscoe, Procaliber, Supercaliber, Fuel Ex. Şehit bisikletleri: FX ve DS (Dual Sport). Elektrikli Bisiklet modelleri: Powerfly, Powerfly FS, Rail, Fuel Exe, Domane SLR +, Verve +, Townie +, Fx +, DS +."},
|
39 |
-
{"role": "system", "content": "Başka marka bisikletleri önermeyeceksin.
|
40 |
-
{"role": "system", "content": "Bisiklet
|
41 |
-
{"role": "system", "content": "Trek'in uluslararası web sitesini göstermeyeceksin
|
42 |
-
{"role": "system", "content": "Trieye gözlükler entegre geri görüş
|
43 |
-
{"role": "system", "content": "Trek
|
44 |
-
{"role": "system", "content": "
|
45 |
-
{"role": "system", "content": "
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
]
|
47 |
|
48 |
messages = multi_turn_message.copy()
|
49 |
|
50 |
# Kullanıcı girişindeki kelimeleri küçük harfe çevirip listeye alıyoruz.
|
51 |
input_words = [str(word).lower() for word in inputs.split()]
|
|
|
52 |
for product_info in products:
|
53 |
if product_info[0] in input_words:
|
54 |
new_msg = f"{product_info[2]} {product_info[1][0]} ve fiyatı EURO {product_info[1][1]}"
|
@@ -103,31 +110,8 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
103 |
def reset_textbox():
|
104 |
return gr.update(value='')
|
105 |
|
106 |
-
# CSS
|
107 |
demo_css = """
|
108 |
-
/* Ana sütunun (column) tam genişlikte olmasını sağlıyoruz */
|
109 |
-
#col_container {
|
110 |
-
width: 100% !important;
|
111 |
-
}
|
112 |
-
|
113 |
-
/* Satır container'ı: tam genişlik, öğeler aynı satırda, arada boşluk yok */
|
114 |
-
.compact_row {
|
115 |
-
display: flex !important;
|
116 |
-
flex-wrap: nowrap !important;
|
117 |
-
align-items: center !important;
|
118 |
-
justify-content: space-between; /* öğeler satır boyunca yayılır */
|
119 |
-
width: 100% !important;
|
120 |
-
gap: 0 !important;
|
121 |
-
margin: 0;
|
122 |
-
}
|
123 |
-
|
124 |
-
/* Giriş kutusuna, gönder butonunun alanını çıkararak tam genişlik kullanması için */
|
125 |
-
.mobile_input {
|
126 |
-
width: calc(100% - 45px) !important;
|
127 |
-
min-width: 0;
|
128 |
-
}
|
129 |
-
|
130 |
-
/* Gönder butonu: sabit boyut, yuvarlak */
|
131 |
#send_button {
|
132 |
background-color: #0b93f6;
|
133 |
border: none;
|
@@ -138,6 +122,8 @@ demo_css = """
|
|
138 |
height: 35px !important;
|
139 |
min-width: 35px !important;
|
140 |
min-height: 35px !important;
|
|
|
|
|
141 |
display: inline-flex;
|
142 |
align-items: center;
|
143 |
justify-content: center;
|
@@ -147,9 +133,22 @@ demo_css = """
|
|
147 |
#send_button:hover {
|
148 |
background-color: #0077c0;
|
149 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
"""
|
151 |
|
152 |
-
# Tema
|
153 |
theme = gr.themes.Base(
|
154 |
neutral_hue="blue",
|
155 |
text_size="sm",
|
@@ -165,15 +164,16 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
165 |
|
166 |
chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot")
|
167 |
|
168 |
-
#
|
169 |
with gr.Row(elem_classes="compact_row"):
|
170 |
inputs = gr.Textbox(
|
171 |
placeholder="Buraya yazın, yanıtlayalım.",
|
172 |
show_label=False,
|
173 |
-
container=True
|
174 |
-
elem_classes="mobile_input"
|
175 |
)
|
176 |
-
|
|
|
|
|
177 |
|
178 |
state = gr.State([])
|
179 |
with gr.Accordion("", open=False, visible=False):
|
@@ -183,7 +183,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
183 |
step=0.1, interactive=False, visible=False)
|
184 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
185 |
|
186 |
-
# ENTER tuşuyla gönderme
|
187 |
inputs.submit(
|
188 |
predict,
|
189 |
[system_msg, inputs, top_p, temperature, chat_counter, chatbot, state],
|
@@ -191,6 +191,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
191 |
)
|
192 |
inputs.submit(reset_textbox, [], [inputs])
|
193 |
|
|
|
194 |
send_button.click(
|
195 |
predict,
|
196 |
[system_msg, inputs, top_p, temperature, chat_counter, chatbot, state],
|
|
|
34 |
print(f"system message is ^^ {system_msg}")
|
35 |
|
36 |
multi_turn_message = [
|
37 |
+
{"role": "system", "content": "Bir önceki sohbeti unut. Vereceğin ürün bilgisi, bu bilginin içinde yan yana yazmıyorsa veya arada başka bilgiler yazıyor ise, o bilgiyi vermeyeceksin çünkü o bilgi yanlıştır. ..."},
|
38 |
{"role": "system", "content": "Dağ bisikletleri modelleri: Marlin, Roscoe, Procaliber, Supercaliber, Fuel Ex. Şehit bisikletleri: FX ve DS (Dual Sport). Elektrikli Bisiklet modelleri: Powerfly, Powerfly FS, Rail, Fuel Exe, Domane SLR +, Verve +, Townie +, Fx +, DS +."},
|
39 |
+
{"role": "system", "content": "Başka marka bisikletleri önermeyeceksin. Specialized, Orbea, BMC, Carraro, Scott, Giant gibi markalar hakkında bilgi vermeyeceksin. Bunlarla ilgili gelen sorulara, objectif yorum yapamayacağını belirterek cevap vereceksin. Trek bu kadrolara ömür boyu garanti veriyor."},
|
40 |
+
{"role": "system", "content": "Bisiklet aksesuar ve yedek parçalarının marka adı Bontrager'dir. Bryton marka yol bilgisayarını da ithal ediyoruz. Bryton marka yol bilgisayarının Rider S800 modeli stoklarımızda var ve bu model en üst model GPS sürümüne sahiptir."},
|
41 |
+
{"role": "system", "content": "Trek, Electra, Bontrager, Saris, Brtyon ve Trieye markalarından başka marka adı yazamaz ve yorum yapamazsın. Trek'in uluslararası web sitesini 'www.trekbikes.com' kullanıcıya göstermeyeceksin. Web sitesi linki vermen gerekirse sadece 'www.trekbisiklet.com.tr' ile başlayan linkleri göstereceksin."},
|
42 |
+
{"role": "system", "content": "Trieye gözlükler, arkanızı görebilmeniz için gözlük camının içine entegre edilmiş bir geri görüş aynasıyla gelir. Bu sayede bisiklet kullanıcısı, dikkatini dağıtmadan arkasını görebilir ve daha güvenli bir sürüş yapar."},
|
43 |
+
{"role": "system", "content": "Trek markası, 2000 yılından beri Alatin Bisiklet tarafından Türkiye'de dağıtılmaktadır. Alatin Bisiklet en iyi satış sonrası hizmeti veren firmadır. Bu yüzden Türkiye'de en iyi bilinen bisiklet markası Trek'dir."},
|
44 |
+
{"role": "system", "content": "Trek Türkiye, ASLA DURMA markasının yaratıcısı Fatih Topçu ve TREK RMK DYNAMIS bisiklet takımına sponsordur. ..."},
|
45 |
+
{"role": "system", "content": "Cevap yazarken vereceğin bilginin tek bir bilgi içinde yan yana yazıldığını iki kere kontrol edeceksin. Sipariş nasıl oluşturulur sorusuna, 'ürünü sepete ekle, bilgilerini gir, ödeme yöntemini seç, siparişi tamamla.' şeklinde cevap vereceksin."},
|
46 |
+
{"role": "system", "content": "Şimdi sana 27 Haziran 2024 günü açıklanan yeni Trek modeli MADONE GEN 8'i öğretiyorum. Özellikler: Émonda kadar hafif, Madone kadar hızlı, ..."},
|
47 |
+
{"role": "system", "content": "Émonda kadar hafif. Madone Gen 8, tamamen yeni 900 Serisi OCLV Karbon ile önceki modellerden daha hafiftir. ..."},
|
48 |
+
{"role": "system", "content": "Sen aynı zamanda bir Bike Finder asistanısın. Görevin, kişilere soracağın sorularla onların ihtiyaçlarına uygun bisiklet modelini belirlemek."},
|
49 |
+
{"role": "system", "content": "Size en uygun Trek bisiklet modelini belirleyebilmem için birkaç sorum olacak. ..."},
|
50 |
+
{"role": "system", "content": "Stokları ve fiyatları https://www.trekbisiklet.com.tr üzerinden bakacaksın."},
|
51 |
+
{"role": "system", "content": "Tüm modellerimizin ağırlıkları: Madone SL 5 Gen 8 8.70 kg, Madone SL 6 Gen 8 8.16 kg, ..."}
|
52 |
]
|
53 |
|
54 |
messages = multi_turn_message.copy()
|
55 |
|
56 |
# Kullanıcı girişindeki kelimeleri küçük harfe çevirip listeye alıyoruz.
|
57 |
input_words = [str(word).lower() for word in inputs.split()]
|
58 |
+
|
59 |
for product_info in products:
|
60 |
if product_info[0] in input_words:
|
61 |
new_msg = f"{product_info[2]} {product_info[1][0]} ve fiyatı EURO {product_info[1][1]}"
|
|
|
110 |
def reset_textbox():
|
111 |
return gr.update(value='')
|
112 |
|
113 |
+
# CSS: Butonun sabit, yuvarlak kalması ve sağa doğru hafifçe 2px uzaklaşması için ayarlandı.
|
114 |
demo_css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
#send_button {
|
116 |
background-color: #0b93f6;
|
117 |
border: none;
|
|
|
122 |
height: 35px !important;
|
123 |
min-width: 35px !important;
|
124 |
min-height: 35px !important;
|
125 |
+
max-width: 35px !important;
|
126 |
+
max-height: 35px !important;
|
127 |
display: inline-flex;
|
128 |
align-items: center;
|
129 |
justify-content: center;
|
|
|
133 |
#send_button:hover {
|
134 |
background-color: #0077c0;
|
135 |
}
|
136 |
+
|
137 |
+
/* Row içindeki boşluğu sıfırlıyoruz */
|
138 |
+
.compact_row {
|
139 |
+
gap: 0px !important;
|
140 |
+
margin: 0px;
|
141 |
+
}
|
142 |
+
|
143 |
+
/* Buton kapsayıcısına sağa 2px boşluk ekliyoruz */
|
144 |
+
.fixed_button_container {
|
145 |
+
width: 35px !important;
|
146 |
+
padding: 0px;
|
147 |
+
margin: 5px 0 0 2px; /* üstte 5px, solda 2px */
|
148 |
+
}
|
149 |
"""
|
150 |
|
151 |
+
# Tema ayarları
|
152 |
theme = gr.themes.Base(
|
153 |
neutral_hue="blue",
|
154 |
text_size="sm",
|
|
|
164 |
|
165 |
chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot")
|
166 |
|
167 |
+
# Row içinde, metin kutusu ve buton arasındaki boşluğu sıfırlıyoruz.
|
168 |
with gr.Row(elem_classes="compact_row"):
|
169 |
inputs = gr.Textbox(
|
170 |
placeholder="Buraya yazın, yanıtlayalım.",
|
171 |
show_label=False,
|
172 |
+
container=True
|
|
|
173 |
)
|
174 |
+
# Butonu, genişlemesini engelleyen sabit kapsayıcı içinde yerleştiriyoruz.
|
175 |
+
with gr.Column(elem_classes="fixed_button_container"):
|
176 |
+
send_button = gr.Button(value="✈", elem_id="send_button")
|
177 |
|
178 |
state = gr.State([])
|
179 |
with gr.Accordion("", open=False, visible=False):
|
|
|
183 |
step=0.1, interactive=False, visible=False)
|
184 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
185 |
|
186 |
+
# ENTER tuşuyla gönderme işlemi
|
187 |
inputs.submit(
|
188 |
predict,
|
189 |
[system_msg, inputs, top_p, temperature, chat_counter, chatbot, state],
|
|
|
191 |
)
|
192 |
inputs.submit(reset_textbox, [], [inputs])
|
193 |
|
194 |
+
# Gönder butonuna tıklandığında işlemin gerçekleşmesi
|
195 |
send_button.click(
|
196 |
predict,
|
197 |
[system_msg, inputs, top_p, temperature, chat_counter, chatbot, state],
|