Spaces:
Running
Running
File size: 1,802 Bytes
75b8dbb 770f650 75b8dbb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | import os
import sys
import time
import threading
import queue
if sys.stdout and hasattr(sys.stdout, 'reconfigure'):
sys.stdout.reconfigure(encoding='utf-8')
from kaggle_auth import init_kaggle_auth
init_kaggle_auth()
from kaggle.api.kaggle_api_extended import KaggleApi
def main():
api = KaggleApi()
api.authenticate()
q = queue.Queue()
stop_event = threading.Event()
def worker():
try:
for event in api.kernels_logs_stream('gustavnguyen/paddleocr-cham-finetune'):
if stop_event.is_set():
break
data = event.get('data', '')
if data:
q.put(data)
except Exception:
pass
t = threading.Thread(target=worker, daemon=True)
t.start()
raw_text = []
# Thu thập tất cả log đã có (cho đến khi không còn event mới trong 3 giây)
t_start = time.time()
last_recv = time.time()
while time.time() - t_start < 20:
try:
chunk = q.get(timeout=2.0)
raw_text.append(chunk)
last_recv = time.time()
except queue.Empty:
if raw_text and (time.time() - last_recv > 3.0):
# Đã đọc hết log hiện có
break
stop_event.set()
full_str = "".join(raw_text)
clean_lines = []
for line in full_str.splitlines():
l = line.strip()
if l and 'MB/s' not in l and 'â”' not in l and not l.startswith('\x1b['):
clean_lines.append(l)
print(f"📊 Thu thập được {len(clean_lines)} dòng log từ Kaggle:")
print("="*70)
for l in clean_lines[-40:]:
print(l)
print("="*70)
if __name__ == '__main__':
main()
|