SamiKoen commited on
Commit
bd1a474
·
verified ·
1 Parent(s): 0756309

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -33,10 +33,6 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
33
  }
34
  print(f"system message is ^^ {system_msg}")
35
 
36
- # İlk kullanıcı mesajı (örnek amaçlı)
37
- initial_message = [{"role": "user", "content": f"{inputs}"}]
38
-
39
- # Çoklu sohbet mesajları – Buraya verilen metinleri ihtiyaçlarınıza göre düzenleyebilirsiniz.
40
  multi_turn_message = [
41
  {"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. ..."},
42
  {"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 +."},
@@ -60,7 +56,7 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
60
  # Kullanıcı girişindeki kelimeleri küçük harfe çevirip listeye alıyoruz.
61
  input_words = [str(word).lower() for word in inputs.split()]
62
 
63
- # Eğer kullanıcının girişinde ürün isminden birine rastlanırsa, ilgili ürün bilgisini sisteme ekliyoruz.
64
  for product_info in products:
65
  if product_info[0] in input_words:
66
  new_msg = f"{product_info[2]} {product_info[1][0]} ve fiyatı EURO {product_info[1][1]}"
@@ -75,7 +71,7 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
75
  messages.append(user_msg)
76
  messages.append(assistant_msg)
77
 
78
- # Son olarak, mevcut kullanıcı girişini de ekliyoruz.
79
  messages.append({"role": "user", "content": inputs})
80
 
81
  payload = {
@@ -104,7 +100,6 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
104
  continue
105
  if chunk.decode():
106
  chunk = chunk.decode()
107
- # Gelen veri içerisinde "content" varsa ekliyoruz.
108
  if len(chunk) > 12 and "content" in json.loads(chunk[6:])['choices'][0]['delta']:
109
  partial_words += json.loads(chunk[6:])['choices'][0]["delta"]["content"]
110
  if token_counter == 0:
@@ -118,17 +113,29 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
118
  def reset_textbox():
119
  return gr.update(value='')
120
 
121
- # CSS: Gönder butonunun stilini belirleyen kod
122
  demo_css = """
123
  #send_button {
124
- background-color: transparent;
125
  border: none;
 
126
  font-size: 24px;
 
 
 
 
 
 
127
  cursor: pointer;
128
- padding: 0 10px;
129
  }
130
  #send_button:hover {
131
- color: #0b93f6;
 
 
 
 
 
132
  }
133
  """
134
 
@@ -141,7 +148,6 @@ theme = gr.themes.Base(
141
 
142
  with gr.Blocks(css=demo_css, theme=theme) as demo:
143
  with gr.Column(elem_id="col_container"):
144
- # Gizli ayarların bulunduğu alan (Accordion) – isteğe bağlı
145
  with gr.Accordion("", open=False, visible=False):
146
  system_msg = gr.Textbox(value="")
147
  new_msg = gr.Textbox(value="")
@@ -149,13 +155,14 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
149
 
150
  chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot")
151
 
152
- # Giriş kutusu ve gönder butonunu aynı satıra alıyoruz.
153
- with gr.Row(variant="compact"):
154
  inputs = gr.Textbox(
155
  placeholder="Buraya yazın, yanıtlayalım.",
156
  show_label=False,
157
  container=True
158
  )
 
159
  send_button = gr.Button(value="⇨", elem_id="send_button")
160
 
161
  state = gr.State([])
@@ -166,7 +173,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
166
  step=0.1, interactive=False, visible=False)
167
  chat_counter = gr.Number(value=0, visible=False, precision=0)
168
 
169
- # Kullanıcı ENTER tuşuyla gönderdiğinde çalışacak işlemler
170
  inputs.submit(
171
  predict,
172
  [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state],
 
33
  }
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 +."},
 
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
+ # Eğer kullanıcının girişinde ürün isminden birine rastlanırsa, ilgili ürün bilgisini ekliyoruz.
60
  for product_info in products:
61
  if product_info[0] in input_words:
62
  new_msg = f"{product_info[2]} {product_info[1][0]} ve fiyatı EURO {product_info[1][1]}"
 
71
  messages.append(user_msg)
72
  messages.append(assistant_msg)
73
 
74
+ # Mevcut kullanıcı girişini ekliyoruz.
75
  messages.append({"role": "user", "content": inputs})
76
 
77
  payload = {
 
100
  continue
101
  if chunk.decode():
102
  chunk = chunk.decode()
 
103
  if len(chunk) > 12 and "content" in json.loads(chunk[6:])['choices'][0]['delta']:
104
  partial_words += json.loads(chunk[6:])['choices'][0]["delta"]["content"]
105
  if token_counter == 0:
 
113
  def reset_textbox():
114
  return gr.update(value='')
115
 
116
+ # CSS: Buton stilinin yanı sıra özel satır sınıfıyla gap (boşluk) sıfırlanıyor.
117
  demo_css = """
118
  #send_button {
119
+ background-color: #0b93f6;
120
  border: none;
121
+ color: white;
122
  font-size: 24px;
123
+ border-radius: 50%;
124
+ width: 50px;
125
+ height: 50px;
126
+ display: flex;
127
+ align-items: center;
128
+ justify-content: center;
129
  cursor: pointer;
130
+ transition: background-color 0.3s;
131
  }
132
  #send_button:hover {
133
+ background-color: #0077c0;
134
+ }
135
+ /* Özel satır için gap değerini sıfırlıyoruz */
136
+ .compact_row {
137
+ gap: 0px !important;
138
+ margin: 0px;
139
  }
140
  """
141
 
 
148
 
149
  with gr.Blocks(css=demo_css, theme=theme) as demo:
150
  with gr.Column(elem_id="col_container"):
 
151
  with gr.Accordion("", open=False, visible=False):
152
  system_msg = gr.Textbox(value="")
153
  new_msg = gr.Textbox(value="")
 
155
 
156
  chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot")
157
 
158
+ # Özel sınıf (compact_row) kullanarak metin kutusu ile buton arasındaki boşluğu kaldırıyoruz.
159
+ with gr.Row(elem_classes="compact_row"):
160
  inputs = gr.Textbox(
161
  placeholder="Buraya yazın, yanıtlayalım.",
162
  show_label=False,
163
  container=True
164
  )
165
+ # Buton içeriğinde doğrudan Unicode "✈" karakterini kullanıyoruz.
166
  send_button = gr.Button(value="⇨", elem_id="send_button")
167
 
168
  state = gr.State([])
 
173
  step=0.1, interactive=False, visible=False)
174
  chat_counter = gr.Number(value=0, visible=False, precision=0)
175
 
176
+ # ENTER tuşu ile gönderme işlemleri.
177
  inputs.submit(
178
  predict,
179
  [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state],