Update app.py
Browse files
app.py
CHANGED
@@ -195,7 +195,7 @@ def save_chat_and_upload(chatbot):
|
|
195 |
|
196 |
# Gradio arayüzü
|
197 |
demo_css = """
|
198 |
-
#send_button {
|
199 |
background-color: #0b93f6;
|
200 |
border: none;
|
201 |
color: white;
|
@@ -210,7 +210,7 @@ demo_css = """
|
|
210 |
transition: background-color 0.3s;
|
211 |
margin: 5px;
|
212 |
}
|
213 |
-
#send_button:hover {
|
214 |
background-color: #0077c0;
|
215 |
}
|
216 |
.fixed_button_container {
|
@@ -238,34 +238,7 @@ theme = gr.themes.Base(
|
|
238 |
spacing_size="sm",
|
239 |
)
|
240 |
|
241 |
-
|
242 |
-
function loadChat() {
|
243 |
-
const chatHistory = localStorage.getItem('chatHistory');
|
244 |
-
if (chatHistory) {
|
245 |
-
try {
|
246 |
-
const parsedHistory = JSON.parse(chatHistory);
|
247 |
-
if (Array.isArray(parsedHistory)) {
|
248 |
-
// Her öğenin 'role' ve 'content' anahtarlarına sahip bir sözlük olduğunu kontrol et
|
249 |
-
if (parsedHistory.every(item => typeof item === 'object' && item !== null && 'role' in item && 'content' in item)) {
|
250 |
-
return parsedHistory;
|
251 |
-
} else {
|
252 |
-
console.error('localStorage: Chat history items are not in the correct format.');
|
253 |
-
return [];
|
254 |
-
}
|
255 |
-
} else {
|
256 |
-
console.error('localStorage: Chat history is not an array.');
|
257 |
-
return [];
|
258 |
-
}
|
259 |
-
} catch (e) {
|
260 |
-
console.error('localStorage: Error parsing chat history:', e);
|
261 |
-
return [];
|
262 |
-
}
|
263 |
-
}
|
264 |
-
return [];
|
265 |
-
}
|
266 |
-
"""
|
267 |
-
|
268 |
-
with gr.Blocks(css=demo_css, theme=theme, head=f"<script>{js_code}</script>") as demo: #custom_head yerine head parametresi kullanıldı.
|
269 |
if not os.path.exists(LOG_FILE):
|
270 |
with open(LOG_FILE, 'w', encoding='utf-8') as f:
|
271 |
f.write("--- Yeni Sohbet ---\n")
|
@@ -276,16 +249,16 @@ with gr.Blocks(css=demo_css, theme=theme, head=f"<script>{js_code}</script>") as
|
|
276 |
new_msg = gr.Textbox(value="")
|
277 |
accordion_msg = gr.HTML(value="", visible=False)
|
278 |
|
279 |
-
chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot", type="messages"
|
280 |
|
281 |
with gr.Row(elem_id="custom_row"):
|
282 |
inputs = gr.Textbox(
|
283 |
-
placeholder="Buraya
|
284 |
show_label=False,
|
285 |
container=False,
|
286 |
)
|
287 |
with gr.Column(elem_classes="fixed_button_container"):
|
288 |
-
send_button = gr.Button(value="
|
289 |
|
290 |
state = gr.State([])
|
291 |
|
@@ -299,6 +272,5 @@ with gr.Blocks(css=demo_css, theme=theme, head=f"<script>{js_code}</script>") as
|
|
299 |
send_button.click(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter])
|
300 |
send_button.click(reset_textbox, [], [inputs])
|
301 |
send_button.click(save_chat_and_upload, [chatbot], [])
|
302 |
-
send_button.click(None, [chatbot], None, _js="saveChat") # her mesaj gönderildiğinde saveChat fonksiyonunu çağır
|
303 |
|
304 |
demo.queue(max_size=10).launch(debug=True)
|
|
|
195 |
|
196 |
# Gradio arayüzü
|
197 |
demo_css = """
|
198 |
+
#send_button, #save_button {
|
199 |
background-color: #0b93f6;
|
200 |
border: none;
|
201 |
color: white;
|
|
|
210 |
transition: background-color 0.3s;
|
211 |
margin: 5px;
|
212 |
}
|
213 |
+
#send_button:hover, #save_button:hover {
|
214 |
background-color: #0077c0;
|
215 |
}
|
216 |
.fixed_button_container {
|
|
|
238 |
spacing_size="sm",
|
239 |
)
|
240 |
|
241 |
+
with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
if not os.path.exists(LOG_FILE):
|
243 |
with open(LOG_FILE, 'w', encoding='utf-8') as f:
|
244 |
f.write("--- Yeni Sohbet ---\n")
|
|
|
249 |
new_msg = gr.Textbox(value="")
|
250 |
accordion_msg = gr.HTML(value="", visible=False)
|
251 |
|
252 |
+
chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot", type="messages")
|
253 |
|
254 |
with gr.Row(elem_id="custom_row"):
|
255 |
inputs = gr.Textbox(
|
256 |
+
placeholder="Buraya yazıp, entera basın",
|
257 |
show_label=False,
|
258 |
container=False,
|
259 |
)
|
260 |
with gr.Column(elem_classes="fixed_button_container"):
|
261 |
+
send_button = gr.Button(value="Kapat", elem_id="send_button")
|
262 |
|
263 |
state = gr.State([])
|
264 |
|
|
|
272 |
send_button.click(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter])
|
273 |
send_button.click(reset_textbox, [], [inputs])
|
274 |
send_button.click(save_chat_and_upload, [chatbot], [])
|
|
|
275 |
|
276 |
demo.queue(max_size=10).launch(debug=True)
|