Update app.py
Browse files
app.py
CHANGED
@@ -56,7 +56,6 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
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]}"
|
@@ -64,14 +63,12 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
64 |
product_msg = {"role": "system", "content": new_msg}
|
65 |
messages.append(product_msg)
|
66 |
|
67 |
-
# Daha önceki sohbet geçmişini ekliyoruz.
|
68 |
for data in chatbot:
|
69 |
user_msg = {"role": "user", "content": data[0]}
|
70 |
assistant_msg = {"role": "assistant", "content": data[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 = {
|
@@ -84,11 +81,11 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
84 |
"presence_penalty": 0,
|
85 |
"frequency_penalty": 0,
|
86 |
}
|
87 |
-
|
88 |
chat_counter += 1
|
89 |
history.append(inputs)
|
90 |
print(f"Logging : payload is - {payload}")
|
91 |
-
|
92 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
93 |
print(f"Logging : response code - {response}")
|
94 |
token_counter = 0
|
@@ -113,7 +110,7 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
113 |
def reset_textbox():
|
114 |
return gr.update(value='')
|
115 |
|
116 |
-
# CSS: Butonun genişlemesini engellemek ve
|
117 |
demo_css = """
|
118 |
#send_button {
|
119 |
background-color: #0b93f6;
|
@@ -123,26 +120,35 @@ demo_css = """
|
|
123 |
border-radius: 50%;
|
124 |
width: 35px !important;
|
125 |
height: 35px !important;
|
|
|
|
|
|
|
|
|
126 |
display: inline-flex;
|
127 |
align-items: center;
|
128 |
justify-content: center;
|
129 |
cursor: pointer;
|
130 |
transition: background-color 0.3s;
|
131 |
-
flex-grow: 0 !important;
|
132 |
-
flex-shrink: 0 !important;
|
133 |
}
|
134 |
#send_button:hover {
|
135 |
background-color: #0077c0;
|
136 |
}
|
137 |
|
138 |
-
/* Row
|
139 |
.compact_row {
|
140 |
gap: 0px !important;
|
141 |
margin: 0px;
|
142 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
"""
|
144 |
|
145 |
-
# Tema ayarları
|
146 |
theme = gr.themes.Base(
|
147 |
neutral_hue="blue",
|
148 |
text_size="sm",
|
@@ -155,18 +161,20 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
155 |
system_msg = gr.Textbox(value="")
|
156 |
new_msg = gr.Textbox(value="")
|
157 |
accordion_msg = gr.HTML(value="", visible=False)
|
158 |
-
|
159 |
chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot")
|
160 |
|
161 |
-
#
|
162 |
with gr.Row(elem_classes="compact_row"):
|
163 |
inputs = gr.Textbox(
|
164 |
placeholder="Buraya yazın, yanıtlayalım.",
|
165 |
show_label=False,
|
166 |
container=True
|
167 |
)
|
168 |
-
|
169 |
-
|
|
|
|
|
170 |
state = gr.State([])
|
171 |
with gr.Accordion("", open=False, visible=False):
|
172 |
top_p = gr.Slider(minimum=0, maximum=1.0, value=0.5,
|
@@ -175,7 +183,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
175 |
step=0.1, interactive=False, visible=False)
|
176 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
177 |
|
178 |
-
# ENTER
|
179 |
inputs.submit(
|
180 |
predict,
|
181 |
[system_msg, inputs, top_p, temperature, chat_counter, chatbot, state],
|
@@ -183,7 +191,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
183 |
)
|
184 |
inputs.submit(reset_textbox, [], [inputs])
|
185 |
|
186 |
-
# Gönder butonuna tıklandığında
|
187 |
send_button.click(
|
188 |
predict,
|
189 |
[system_msg, inputs, top_p, temperature, chat_counter, chatbot, state],
|
|
|
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]}"
|
|
|
63 |
product_msg = {"role": "system", "content": new_msg}
|
64 |
messages.append(product_msg)
|
65 |
|
|
|
66 |
for data in chatbot:
|
67 |
user_msg = {"role": "user", "content": data[0]}
|
68 |
assistant_msg = {"role": "assistant", "content": data[1]}
|
69 |
messages.append(user_msg)
|
70 |
messages.append(assistant_msg)
|
71 |
|
|
|
72 |
messages.append({"role": "user", "content": inputs})
|
73 |
|
74 |
payload = {
|
|
|
81 |
"presence_penalty": 0,
|
82 |
"frequency_penalty": 0,
|
83 |
}
|
84 |
+
|
85 |
chat_counter += 1
|
86 |
history.append(inputs)
|
87 |
print(f"Logging : payload is - {payload}")
|
88 |
+
|
89 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
90 |
print(f"Logging : response code - {response}")
|
91 |
token_counter = 0
|
|
|
110 |
def reset_textbox():
|
111 |
return gr.update(value='')
|
112 |
|
113 |
+
# CSS: Butonun genişlemesini engellemek ve sabit, yuvarlak kalmasını sağlamak için gerekli ayarlamalar yapıldı.
|
114 |
demo_css = """
|
115 |
#send_button {
|
116 |
background-color: #0b93f6;
|
|
|
120 |
border-radius: 50%;
|
121 |
width: 35px !important;
|
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;
|
130 |
cursor: pointer;
|
131 |
transition: background-color 0.3s;
|
|
|
|
|
132 |
}
|
133 |
#send_button:hover {
|
134 |
background-color: #0077c0;
|
135 |
}
|
136 |
|
137 |
+
/* Kapsayıcı Row için boşlukları kaldırıyoruz */
|
138 |
.compact_row {
|
139 |
gap: 0px !important;
|
140 |
margin: 0px;
|
141 |
}
|
142 |
+
|
143 |
+
/* Buton için sabit kapsayıcı, genişlemesini engellemek amacıyla */
|
144 |
+
.fixed_button_container {
|
145 |
+
width: 35px !important;
|
146 |
+
padding: 0px;
|
147 |
+
margin: 0px;
|
148 |
+
}
|
149 |
"""
|
150 |
|
151 |
+
# Tema ayarları
|
152 |
theme = gr.themes.Base(
|
153 |
neutral_hue="blue",
|
154 |
text_size="sm",
|
|
|
161 |
system_msg = gr.Textbox(value="")
|
162 |
new_msg = gr.Textbox(value="")
|
163 |
accordion_msg = gr.HTML(value="", visible=False)
|
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 kaldırı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):
|
180 |
top_p = gr.Slider(minimum=0, maximum=1.0, value=0.5,
|
|
|
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],
|