SamiKoen commited on
Commit
60b2cc4
·
verified ·
1 Parent(s): 852d7e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -79,7 +79,7 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
79
  history.append(inputs)
80
  print(f"Logging: Payload is - {payload}")
81
 
82
- # Kullanıcı mesajını anında yazma (isteğe bağlı, kaldırılabilir)
83
  try:
84
  with open(LOG_FILE, 'a', encoding='utf-8') as f:
85
  f.write(f"User: {inputs}\n")
@@ -113,7 +113,7 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
113
  token_counter += 1
114
  yield chat, history, chat_counter, response
115
 
116
- # Bot yanıtını anında yazma (isteğe bağlı, kaldırılabilir)
117
  try:
118
  with open(LOG_FILE, 'a', encoding='utf-8') as f:
119
  f.write(f"Bot: {partial_words}\n")
@@ -123,17 +123,18 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=[], hi
123
 
124
  def save_chat(chatbot):
125
  """ Sohbeti dosyaya kaydetme fonksiyonu """
 
126
  try:
127
  with open(LOG_FILE, 'a', encoding='utf-8') as f:
128
  f.write("\n--- Kayıt Edilen Sohbet ---\n")
129
  for user_msg, bot_msg in chatbot:
130
  f.write(f"User: {user_msg}\n")
131
  f.write(f"Bot: {bot_msg}\n")
132
- print("Sohbet dosyaya kaydedildi.")
133
- return "Sohbet başarıyla kaydedildi!"
134
  except Exception as e:
135
  print(f"Kayıt hatası: {e}")
136
- return f"Kayıt hatası: {e}"
137
 
138
  def reset_textbox():
139
  return gr.update(value='')
@@ -203,7 +204,7 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
203
  )
204
  with gr.Column(elem_classes="fixed_button_container"):
205
  send_button = gr.Button(value="Gönder", elem_id="send_button")
206
- save_button = gr.Button(value="Kayıt Et", elem_id="save_button") # Yeni tuş
207
 
208
  state = gr.State([])
209
  save_status = gr.Textbox(label="Kayıt Durumu", interactive=False) # Kayıt durumu için geri bildirim
 
79
  history.append(inputs)
80
  print(f"Logging: Payload is - {payload}")
81
 
82
+ # Kullanıcı mesajını anında yazma (isteğe bağlı)
83
  try:
84
  with open(LOG_FILE, 'a', encoding='utf-8') as f:
85
  f.write(f"User: {inputs}\n")
 
113
  token_counter += 1
114
  yield chat, history, chat_counter, response
115
 
116
+ # Bot yanıtını anında yazma (isteğe bağlı)
117
  try:
118
  with open(LOG_FILE, 'a', encoding='utf-8') as f:
119
  f.write(f"Bot: {partial_words}\n")
 
123
 
124
  def save_chat(chatbot):
125
  """ Sohbeti dosyaya kaydetme fonksiyonu """
126
+ file_path = os.path.abspath(LOG_FILE) # Dosyanın tam yolunu al
127
  try:
128
  with open(LOG_FILE, 'a', encoding='utf-8') as f:
129
  f.write("\n--- Kayıt Edilen Sohbet ---\n")
130
  for user_msg, bot_msg in chatbot:
131
  f.write(f"User: {user_msg}\n")
132
  f.write(f"Bot: {bot_msg}\n")
133
+ print(f"Sohbet dosyaya kaydedildi: {file_path}")
134
+ return f"Sohbet başarıyla kaydedildi!\nDosya: {file_path}"
135
  except Exception as e:
136
  print(f"Kayıt hatası: {e}")
137
+ return f"Kayıt hatası: {e}\nDosya: {file_path}"
138
 
139
  def reset_textbox():
140
  return gr.update(value='')
 
204
  )
205
  with gr.Column(elem_classes="fixed_button_container"):
206
  send_button = gr.Button(value="Gönder", elem_id="send_button")
207
+ save_button = gr.Button(value="Kayıt Et", elem_id="save_button")
208
 
209
  state = gr.State([])
210
  save_status = gr.Textbox(label="Kayıt Durumu", interactive=False) # Kayıt durumu için geri bildirim