Update app.py
Browse files
app.py
CHANGED
@@ -41,24 +41,26 @@ for item in root.findall('item'):
|
|
41 |
item_info = (stockAmount, price)
|
42 |
products.append((name, item_info, full_name))
|
43 |
|
44 |
-
# Ortam değişkeninde "hfapi" tanımlı;
|
45 |
hfapi = os.getenv("hfapi")
|
46 |
if not hfapi:
|
47 |
raise ValueError("hfapi ortam değişkeni ayarlanmamış!")
|
48 |
|
49 |
-
# Ana Space için repo oluşturuluyor (repo adı "BF")
|
50 |
create_repo("BF", token=hfapi, repo_type="space", space_sdk="gradio", exist_ok=True)
|
51 |
-
|
|
|
|
|
52 |
|
53 |
def upload_logs_to_hf(repo_id: str, hf_token: str, local_log_file: str = "chat_logs.txt", repo_type: str = "model"):
|
54 |
"""
|
55 |
Log dosyasını HF Hub'daki ayrı bir repository'ye yükler.
|
56 |
|
57 |
Args:
|
58 |
-
repo_id (str): Log repository
|
59 |
hf_token (str): HF API token'ınız.
|
60 |
local_log_file (str): Yüklenecek log dosyasının yolu.
|
61 |
-
repo_type (str): Repository tipi
|
62 |
"""
|
63 |
api = HfApi(token=hf_token)
|
64 |
try:
|
@@ -75,9 +77,9 @@ def upload_logs_to_hf(repo_id: str, hf_token: str, local_log_file: str = "chat_l
|
|
75 |
|
76 |
def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None, history=None):
|
77 |
"""
|
78 |
-
Her Enter'a basıldığında çalışır
|
79 |
-
|
80 |
-
|
81 |
"""
|
82 |
if chatbot is None:
|
83 |
chatbot = []
|
@@ -175,8 +177,8 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
175 |
yield chat, history, chat_counter
|
176 |
|
177 |
print(f"Son chatbot durumu: {chatbot}")
|
178 |
-
#
|
179 |
-
upload_logs_to_hf(
|
180 |
return chatbot, history, chat_counter
|
181 |
|
182 |
def reset_textbox():
|
@@ -245,7 +247,6 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
245 |
)
|
246 |
with gr.Column(elem_classes="fixed_button_container"):
|
247 |
send_button = gr.Button(value="Gönder", elem_id="send_button")
|
248 |
-
# Kayıt Et butonu kaldırıldı.
|
249 |
|
250 |
state = gr.State([])
|
251 |
|
@@ -255,9 +256,9 @@ with gr.Blocks(css=demo_css, theme=theme) as demo:
|
|
255 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
256 |
|
257 |
# Hem Enter hem de Gönder butonuna basıldığında predict çalışıyor.
|
258 |
-
inputs.submit(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot,
|
259 |
inputs.submit(reset_textbox, [], [inputs])
|
260 |
-
send_button.click(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot,
|
261 |
send_button.click(reset_textbox, [], [inputs])
|
262 |
|
263 |
demo.queue(max_size=10).launch(debug=True)
|
|
|
41 |
item_info = (stockAmount, price)
|
42 |
products.append((name, item_info, full_name))
|
43 |
|
44 |
+
# Ortam değişkeninde "hfapi" tanımlı; tokenimizi alıyoruz.
|
45 |
hfapi = os.getenv("hfapi")
|
46 |
if not hfapi:
|
47 |
raise ValueError("hfapi ortam değişkeni ayarlanmamış!")
|
48 |
|
49 |
+
# Ana Space için repo oluşturuluyor (repo adı "BF")
|
50 |
create_repo("BF", token=hfapi, repo_type="space", space_sdk="gradio", exist_ok=True)
|
51 |
+
# Log commitleri için ayrı bir repo oluşturuluyor; repo id'yi tam olarak belirtelim:
|
52 |
+
REPO_ID_LOGS = "SamiKoen/BF-logs"
|
53 |
+
create_repo(REPO_ID_LOGS, token=hfapi, repo_type="model", exist_ok=True)
|
54 |
|
55 |
def upload_logs_to_hf(repo_id: str, hf_token: str, local_log_file: str = "chat_logs.txt", repo_type: str = "model"):
|
56 |
"""
|
57 |
Log dosyasını HF Hub'daki ayrı bir repository'ye yükler.
|
58 |
|
59 |
Args:
|
60 |
+
repo_id (str): Log repository tam id'si (örn. "SamiKoen/BF-logs").
|
61 |
hf_token (str): HF API token'ınız.
|
62 |
local_log_file (str): Yüklenecek log dosyasının yolu.
|
63 |
+
repo_type (str): Repository tipi ("model" kullanıyoruz).
|
64 |
"""
|
65 |
api = HfApi(token=hf_token)
|
66 |
try:
|
|
|
77 |
|
78 |
def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None, history=None):
|
79 |
"""
|
80 |
+
Her Enter'a basıldığında çalışır. Kullanıcı mesajı dosyaya yazılır,
|
81 |
+
bot yanıtı tamamlandığında log dosyasına eklenir ve ardından log dosyası
|
82 |
+
HF Hub'daki log deposuna yüklenir.
|
83 |
"""
|
84 |
if chatbot is None:
|
85 |
chatbot = []
|
|
|
177 |
yield chat, history, chat_counter
|
178 |
|
179 |
print(f"Son chatbot durumu: {chatbot}")
|
180 |
+
# Streaming tamamlandıktan sonra log dosyasını ayrı log deposuna yükle (Space'i etkilemeden)
|
181 |
+
upload_logs_to_hf(REPO_ID_LOGS, hfapi, local_log_file=LOG_FILE, repo_type="model")
|
182 |
return chatbot, history, chat_counter
|
183 |
|
184 |
def reset_textbox():
|
|
|
247 |
)
|
248 |
with gr.Column(elem_classes="fixed_button_container"):
|
249 |
send_button = gr.Button(value="Gönder", elem_id="send_button")
|
|
|
250 |
|
251 |
state = gr.State([])
|
252 |
|
|
|
256 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
257 |
|
258 |
# Hem Enter hem de Gönder butonuna basıldığında predict çalışıyor.
|
259 |
+
inputs.submit(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, gr.State([])], [chatbot, gr.State([]), chat_counter])
|
260 |
inputs.submit(reset_textbox, [], [inputs])
|
261 |
+
send_button.click(predict, [system_msg, inputs, top_p, temperature, chat_counter, chatbot, gr.State([])], [chatbot, gr.State([]), chat_counter])
|
262 |
send_button.click(reset_textbox, [], [inputs])
|
263 |
|
264 |
demo.queue(max_size=10).launch(debug=True)
|