Update app.py
Browse files
app.py
CHANGED
@@ -154,9 +154,10 @@ 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ş
|
|
|
160 |
|
161 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
162 |
|
@@ -176,7 +177,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,6 +279,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
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 |
|
|
|
154 |
except Exception as e:
|
155 |
print(f"Dosya yazma hatası (Kullanıcı): {e}")
|
156 |
|
157 |
+
# Kullanıcı mesajını hemen ekleyip chatbot’u güncelle
|
158 |
chatbot.append({"role": "user", "content": inputs})
|
159 |
+
chatbot.append({"role": "assistant", "content": ""}) # Boş assistant mesajı
|
160 |
+
yield chatbot, history, chat_counter # İlk yield ile kullanıcı mesajı görünür
|
161 |
|
162 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
163 |
|
|
|
177 |
delta = chunk_data['choices'][0]['delta']
|
178 |
if 'content' in delta and delta['content']:
|
179 |
partial_response += delta['content']
|
180 |
+
# Son assistant mesajını güncelle
|
181 |
chatbot[-1] = {"role": "assistant", "content": partial_response}
|
182 |
yield chatbot, history, chat_counter
|
183 |
except json.JSONDecodeError as e:
|
|
|
279 |
chatbot_ref[:] = chat
|
280 |
return chat
|
281 |
|
282 |
+
# inputs.submit ve send_button.click içinde reset_textbox’u hemen çağırıyoruz
|
283 |
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])
|
284 |
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])
|
285 |
|