Update app.py
Browse files
app.py
CHANGED
@@ -5,17 +5,15 @@ import requests
|
|
5 |
import xml.etree.ElementTree as ET
|
6 |
from huggingface_hub import HfApi, create_repo
|
7 |
|
8 |
-
#
|
9 |
-
LOG_FILE = '
|
10 |
persistent_dir = '/persistent-storage'
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
print(f"Kalıcı depolama dizini oluşturulamadı: {e}. Geçici dizine geri dönülüyor.")
|
18 |
-
LOG_FILE = 'chat_logs.txt'
|
19 |
|
20 |
print(f"Dosya yolu: {os.path.abspath(LOG_FILE)}")
|
21 |
|
@@ -91,9 +89,8 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
91 |
|
92 |
chat_counter += 1
|
93 |
history.append(inputs)
|
94 |
-
# Debug çıktısı kaldırıldı: print(f"Logging: Payload is - {payload}")
|
95 |
|
96 |
-
# Kullanıcı mesajını
|
97 |
try:
|
98 |
with open(LOG_FILE, 'a', encoding='utf-8') as f:
|
99 |
f.write(f"User: {inputs}\n")
|
@@ -104,7 +101,6 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
104 |
# Chatbot'a kullanıcı mesajını ekle
|
105 |
chatbot.append({"role": "user", "content": inputs})
|
106 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
107 |
-
# Debug çıktısı kaldırıldı: print(f"Logging: Response code - {response.status_code}")
|
108 |
|
109 |
if response.status_code != 200:
|
110 |
print(f"API hatası: {response.text}")
|
@@ -127,7 +123,7 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
127 |
elif chunk_str == "data: [DONE]":
|
128 |
break
|
129 |
|
130 |
-
# Tüm
|
131 |
if assistant_response:
|
132 |
history.append(assistant_response)
|
133 |
chatbot.append({"role": "assistant", "content": assistant_response})
|
@@ -156,7 +152,7 @@ def save_chat(chatbot):
|
|
156 |
def reset_textbox():
|
157 |
return gr.update(value='')
|
158 |
|
159 |
-
def upload_logs_to_hf(repo_id: str, hf_token: str, local_log_file: str = "
|
160 |
"""
|
161 |
Log dosyasını Hugging Face Hub repository'sine yükler.
|
162 |
|
|
|
5 |
import xml.etree.ElementTree as ET
|
6 |
from huggingface_hub import HfApi, create_repo
|
7 |
|
8 |
+
# Log dosyasının adı: "chat_log.txt"
|
9 |
+
LOG_FILE = 'chat_log.txt'
|
10 |
persistent_dir = '/persistent-storage'
|
11 |
|
12 |
+
# Eğer persistent dizini mevcutsa, log dosyasını oraya yerleştiriyoruz.
|
13 |
+
if os.path.exists(persistent_dir):
|
14 |
+
LOG_FILE = os.path.join(persistent_dir, LOG_FILE)
|
15 |
+
else:
|
16 |
+
LOG_FILE = 'chat_log.txt'
|
|
|
|
|
17 |
|
18 |
print(f"Dosya yolu: {os.path.abspath(LOG_FILE)}")
|
19 |
|
|
|
89 |
|
90 |
chat_counter += 1
|
91 |
history.append(inputs)
|
|
|
92 |
|
93 |
+
# Kullanıcı mesajını log dosyasına yazıyoruz
|
94 |
try:
|
95 |
with open(LOG_FILE, 'a', encoding='utf-8') as f:
|
96 |
f.write(f"User: {inputs}\n")
|
|
|
101 |
# Chatbot'a kullanıcı mesajını ekle
|
102 |
chatbot.append({"role": "user", "content": inputs})
|
103 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
|
|
104 |
|
105 |
if response.status_code != 200:
|
106 |
print(f"API hatası: {response.text}")
|
|
|
123 |
elif chunk_str == "data: [DONE]":
|
124 |
break
|
125 |
|
126 |
+
# Tüm yanıtı tek parça halinde log dosyasına yazıyoruz
|
127 |
if assistant_response:
|
128 |
history.append(assistant_response)
|
129 |
chatbot.append({"role": "assistant", "content": assistant_response})
|
|
|
152 |
def reset_textbox():
|
153 |
return gr.update(value='')
|
154 |
|
155 |
+
def upload_logs_to_hf(repo_id: str, hf_token: str, local_log_file: str = "chat_log.txt"):
|
156 |
"""
|
157 |
Log dosyasını Hugging Face Hub repository'sine yükler.
|
158 |
|