Spaces:
Running
on
Zero
Running
on
Zero
Yurii Paniv
commited on
Commit
•
9a7ca97
1
Parent(s):
0eb8092
Log straight away
Browse files
app.py
CHANGED
@@ -26,15 +26,11 @@ def check_thread(logging_queue: Queue):
|
|
26 |
dataset_name=getenv("OUTPUT_DATASET"),
|
27 |
private=True,
|
28 |
)
|
29 |
-
print("Logging thread started.")
|
30 |
-
print(f"Logging to '{getenv('OUTPUT_DATASET')}'")
|
31 |
while True:
|
32 |
-
print("Checking for logs...")
|
33 |
sleep(60)
|
34 |
batch = []
|
35 |
while not logging_queue.empty():
|
36 |
batch.append(logging_queue.get())
|
37 |
-
print("Batch:", batch)
|
38 |
if len(batch) > 0:
|
39 |
try:
|
40 |
logging_callback(batch)
|
@@ -47,10 +43,15 @@ def check_thread(logging_queue: Queue):
|
|
47 |
|
48 |
|
49 |
if getenv("HF_API_TOKEN") is not None:
|
50 |
-
print("Starting logging thread...")
|
51 |
-
log_queue = Queue()
|
52 |
-
t = Thread(target=check_thread, args=(log_queue,))
|
53 |
-
t.start()
|
|
|
|
|
|
|
|
|
|
|
54 |
else:
|
55 |
print("No HF_API_TOKEN found. Logging is disabled.")
|
56 |
|
@@ -83,7 +84,10 @@ def translate(input_text):
|
|
83 |
print(f"{datetime.utcnow()} | Translating: {input_text}")
|
84 |
|
85 |
if getenv("HF_API_TOKEN") is not None:
|
86 |
-
|
|
|
|
|
|
|
87 |
|
88 |
input_text = f"[INST] {input_text} [/INST]"
|
89 |
inputs = tokenizer([input_text], return_tensors="pt").to(model.device)
|
|
|
26 |
dataset_name=getenv("OUTPUT_DATASET"),
|
27 |
private=True,
|
28 |
)
|
|
|
|
|
29 |
while True:
|
|
|
30 |
sleep(60)
|
31 |
batch = []
|
32 |
while not logging_queue.empty():
|
33 |
batch.append(logging_queue.get())
|
|
|
34 |
if len(batch) > 0:
|
35 |
try:
|
36 |
logging_callback(batch)
|
|
|
43 |
|
44 |
|
45 |
if getenv("HF_API_TOKEN") is not None:
|
46 |
+
#print("Starting logging thread...")
|
47 |
+
#log_queue = Queue()
|
48 |
+
#t = Thread(target=check_thread, args=(log_queue,))
|
49 |
+
#t.start()
|
50 |
+
logging_callback = log_data(
|
51 |
+
hf_token=getenv("HF_API_TOKEN"),
|
52 |
+
dataset_name=getenv("OUTPUT_DATASET"),
|
53 |
+
private=True,
|
54 |
+
)
|
55 |
else:
|
56 |
print("No HF_API_TOKEN found. Logging is disabled.")
|
57 |
|
|
|
84 |
print(f"{datetime.utcnow()} | Translating: {input_text}")
|
85 |
|
86 |
if getenv("HF_API_TOKEN") is not None:
|
87 |
+
try:
|
88 |
+
logging_callback([input_text])
|
89 |
+
except:
|
90 |
+
print("Error happened while pushing data to HF.")
|
91 |
|
92 |
input_text = f"[INST] {input_text} [/INST]"
|
93 |
inputs = tokenizer([input_text], return_tensors="pt").to(model.device)
|