Update app.py
Browse files
app.py
CHANGED
@@ -154,9 +154,9 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
154 |
except Exception as e:
|
155 |
print(f"Dosya yazma hatası (Kullanıcı): {e}")
|
156 |
|
157 |
-
# Kullanıcı mesajını
|
158 |
chatbot.append({"role": "user", "content": inputs})
|
159 |
-
chatbot.append({"role": "assistant", "content": ""}) # Boş assistant mesajı
|
160 |
|
161 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
162 |
|
@@ -176,7 +176,7 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
176 |
delta = chunk_data['choices'][0]['delta']
|
177 |
if 'content' in delta and delta['content']:
|
178 |
partial_response += delta['content']
|
179 |
-
# Son assistant mesajını güncelle
|
180 |
chatbot[-1] = {"role": "assistant", "content": partial_response}
|
181 |
yield chatbot, history, chat_counter
|
182 |
except json.JSONDecodeError as e:
|
@@ -278,14 +278,8 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
278 |
chatbot_ref[:] = chat
|
279 |
return chat
|
280 |
|
281 |
-
|
282 |
-
inputs.
|
283 |
-
predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter]
|
284 |
-
).then(update_chatbot_ref, chatbot, chatbot)
|
285 |
-
|
286 |
-
send_button.click(reset_textbox, [], [inputs]).then(
|
287 |
-
predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter]
|
288 |
-
).then(update_chatbot_ref, chatbot, chatbot)
|
289 |
|
290 |
scheduler_thread = threading.Thread(target=run_scheduler, args=(chatbot_ref,), daemon=True)
|
291 |
scheduler_thread.start()
|
|
|
154 |
except Exception as e:
|
155 |
print(f"Dosya yazma hatası (Kullanıcı): {e}")
|
156 |
|
157 |
+
# Kullanıcı mesajını ekledikten sonra, ayrı bir assistant mesajı için yer açıyoruz
|
158 |
chatbot.append({"role": "user", "content": inputs})
|
159 |
+
chatbot.append({"role": "assistant", "content": ""}) # Boş bir assistant mesajı ekliyoruz
|
160 |
|
161 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
162 |
|
|
|
176 |
delta = chunk_data['choices'][0]['delta']
|
177 |
if 'content' in delta and delta['content']:
|
178 |
partial_response += delta['content']
|
179 |
+
# Son assistant mesajını güncelle, önceki mesajları koru
|
180 |
chatbot[-1] = {"role": "assistant", "content": partial_response}
|
181 |
yield chatbot, history, chat_counter
|
182 |
except json.JSONDecodeError as e:
|
|
|
278 |
chatbot_ref[:] = chat
|
279 |
return chat
|
280 |
|
281 |
+
inputs.submit(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter]).then(update_chatbot_ref, chatbot, chatbot).then(reset_textbox, [], [inputs])
|
282 |
+
send_button.click(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter]).then(update_chatbot_ref, chatbot, chatbot).then(reset_textbox, [], [inputs])
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
|
284 |
scheduler_thread = threading.Thread(target=run_scheduler, args=(chatbot_ref,), daemon=True)
|
285 |
scheduler_thread.start()
|