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,7 +238,18 @@ theme = gr.themes.Base(
|
|
238 |
spacing_size="sm",
|
239 |
)
|
240 |
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,7 +260,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
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(
|
@@ -272,5 +283,6 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
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)
|
|
|
195 |
|
196 |
# Gradio arayüzü
|
197 |
demo_css = """
|
198 |
+
#send_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 {
|
214 |
background-color: #0077c0;
|
215 |
}
|
216 |
.fixed_button_container {
|
|
|
238 |
spacing_size="sm",
|
239 |
)
|
240 |
|
241 |
+
js_code = """
|
242 |
+
function saveChat(chat) {
|
243 |
+
localStorage.setItem('chatHistory', JSON.stringify(chat));
|
244 |
+
}
|
245 |
+
|
246 |
+
function loadChat() {
|
247 |
+
const chatHistory = localStorage.getItem('chatHistory');
|
248 |
+
return chatHistory ? JSON.parse(chatHistory) : [];
|
249 |
+
}
|
250 |
+
"""
|
251 |
+
|
252 |
+
with gr.Blocks(css=demo_css, theme=theme, head=f"<script>{js_code}</script>") as demo: #custom_head yerine head parametresi kullanıldı.
|
253 |
if not os.path.exists(LOG_FILE):
|
254 |
with open(LOG_FILE, 'w', encoding='utf-8') as f:
|
255 |
f.write("--- Yeni Sohbet ---\n")
|
|
|
260 |
new_msg = gr.Textbox(value="")
|
261 |
accordion_msg = gr.HTML(value="", visible=False)
|
262 |
|
263 |
+
chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot", type="messages", value="loadChat()")
|
264 |
|
265 |
with gr.Row(elem_id="custom_row"):
|
266 |
inputs = gr.Textbox(
|
|
|
283 |
send_button.click(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter])
|
284 |
send_button.click(reset_textbox, [], [inputs])
|
285 |
send_button.click(save_chat_and_upload, [chatbot], [])
|
286 |
+
send_button.click(None, [chatbot], None, _js="saveChat") # her mesaj gönderildiğinde saveChat fonksiyonunu çağır
|
287 |
|
288 |
demo.queue(max_size=10).launch(debug=True)
|