Update app.py
Browse files
app.py
CHANGED
@@ -71,7 +71,7 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
71 |
}
|
72 |
|
73 |
chat_counter += 1
|
74 |
-
history.append(inputs)
|
75 |
print(f"Logging: Payload is - {payload}")
|
76 |
|
77 |
# Kullanıcı mesajını dosyaya yaz
|
@@ -88,9 +88,9 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
88 |
print(f"API hatası: {response.text}")
|
89 |
return chatbot, history, chat_counter
|
90 |
|
91 |
-
token_counter = 0
|
92 |
partial_words = ""
|
93 |
counter = 0
|
|
|
94 |
for chunk in response.iter_lines():
|
95 |
counter += 1
|
96 |
if not chunk:
|
@@ -113,28 +113,22 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
|
|
113 |
print(f"JSON parse hatası: {e} - Chunk: {chunk_str}")
|
114 |
elif chunk_str == "data: [DONE]":
|
115 |
print("Akış tamamlandı: [DONE] alındı")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
-
# Chatbot
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
[{"role": "assistant", "content": history[i+1]} for i in range(1, len(history), 2)]
|
125 |
-
token_counter += 1
|
126 |
-
yield chat, history, chat_counter
|
127 |
-
|
128 |
-
# Bot yanıtını dosyaya yaz
|
129 |
-
if partial_words:
|
130 |
-
try:
|
131 |
-
with open(LOG_FILE, 'a', encoding='utf-8') as f:
|
132 |
-
f.write(f"Bot: {partial_words}\n")
|
133 |
-
print(f"Bot yanıtı dosyaya yazıldı: {partial_words}")
|
134 |
-
except Exception as e:
|
135 |
-
print(f"Dosya yazma hatası (Bot): {e}")
|
136 |
-
else:
|
137 |
-
print("Uyarı: partial_words boş, bot yanıtı yazılamadı!")
|
138 |
|
139 |
return chat, history, chat_counter
|
140 |
|
@@ -209,7 +203,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
209 |
new_msg = gr.Textbox(value="")
|
210 |
accordion_msg = gr.HTML(value="", visible=False)
|
211 |
|
212 |
-
chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot", type="messages")
|
213 |
|
214 |
with gr.Row(elem_id="custom_row"):
|
215 |
inputs = gr.Textbox(
|
|
|
71 |
}
|
72 |
|
73 |
chat_counter += 1
|
74 |
+
history.append(inputs) # Kullanıcı mesajını ekle
|
75 |
print(f"Logging: Payload is - {payload}")
|
76 |
|
77 |
# Kullanıcı mesajını dosyaya yaz
|
|
|
88 |
print(f"API hatası: {response.text}")
|
89 |
return chatbot, history, chat_counter
|
90 |
|
|
|
91 |
partial_words = ""
|
92 |
counter = 0
|
93 |
+
|
94 |
for chunk in response.iter_lines():
|
95 |
counter += 1
|
96 |
if not chunk:
|
|
|
113 |
print(f"JSON parse hatası: {e} - Chunk: {chunk_str}")
|
114 |
elif chunk_str == "data: [DONE]":
|
115 |
print("Akış tamamlandı: [DONE] alındı")
|
116 |
+
if partial_words:
|
117 |
+
history.append(partial_words) # Bot yanıtını tamamladıktan sonra ekle
|
118 |
+
try:
|
119 |
+
with open(LOG_FILE, 'a', encoding='utf-8') as f:
|
120 |
+
f.write(f"Bot: {partial_words}\n")
|
121 |
+
print(f"Bot yanıtı dosyaya yazıldı: {partial_words}")
|
122 |
+
except Exception as e:
|
123 |
+
print(f"Dosya yazma hatası (Bot): {e}")
|
124 |
|
125 |
+
# Chatbot için geçici güncelleme
|
126 |
+
chat = [{"role": "user", "content": history[i]} for i in range(0, len(history)-1, 2)] + \
|
127 |
+
[{"role": "assistant", "content": history[i+1]} for i in range(1, len(history)-1, 2)]
|
128 |
+
if partial_words and len(history) % 2 != 0: # Bot yanıtı tamamlanmadıysa geçici ekle
|
129 |
+
chat.append({"role": "assistant", "content": partial_words})
|
130 |
+
|
131 |
+
yield chat, history, chat_counter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
return chat, history, chat_counter
|
134 |
|
|
|
203 |
new_msg = gr.Textbox(value="")
|
204 |
accordion_msg = gr.HTML(value="", visible=False)
|
205 |
|
206 |
+
chatbot = gr.Chatbot(label='Trek Asistanı', elem_id="chatbot", type="messages")
|
207 |
|
208 |
with gr.Row(elem_id="custom_row"):
|
209 |
inputs = gr.Textbox(
|