File size: 2,015 Bytes
d6979e5
e68c056
b70cfbb
d6979e5
 
 
 
 
 
 
 
 
 
b70cfbb
 
e68c056
 
 
d6979e5
 
 
 
 
c791eda
 
d6979e5
 
 
 
 
 
 
 
 
 
 
 
 
b70cfbb
 
c791eda
 
d6979e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511bdf3
d6979e5
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import logging
import gradio as gr
import multiprocessing

from src.backend import pull_search_results
from src.envs import (
    API, REPO_ID, START_COMMIT_ID,
    LOG_DIR, HF_CACHE_DIR,
    HF_SEARCH_RESULTS_REPO_DIR, HF_EVAL_RESULTS_REPO_DIR,
    UNZIP_TARGET_DIR,
    TIME_DURATION,
    EVAL_K_VALUES,
)

logger = logging.getLogger(__name__)


def restart_space():
    API.restart_space(repo_id=REPO_ID)


def get_log_files():
    if not os.path.exists(LOG_DIR):
        return []
    return sorted([f for f in os.listdir(LOG_DIR) if f.endswith('.log')])


def refresh_log_files():
    return get_log_files()


def display_log_content(selected_file):
    if selected_file:
        with open(os.path.join(LOG_DIR, selected_file), 'r', encoding='utf-8') as file:
            return file.read()
    return "No log file selected"


if __name__ == "__main__":
    os.makedirs(LOG_DIR, exist_ok=True)
    
    process = multiprocessing.Process(
        target=pull_search_results,
        args=(
            HF_SEARCH_RESULTS_REPO_DIR,
            HF_EVAL_RESULTS_REPO_DIR,
            UNZIP_TARGET_DIR,
            EVAL_K_VALUES,
            HF_CACHE_DIR,
            TIME_DURATION,
            START_COMMIT_ID,
        ),
    )
    process.start()
    
    with gr.Blocks() as demo:
        gr.Markdown("## Select a log file to view its content")
        
        log_file_dropdown = gr.Dropdown(
            choices=refresh_log_files(),
            label="Select log file",
            interactive=True,
        )
        log_content_box = gr.Textbox(
            label="Log content",
            lines=20,
            interactive=False,
        )
        refresh_button = gr.Button("Refresh log files")
        
        log_file_dropdown.change(
            fn=display_log_content,
            inputs=log_file_dropdown,
            outputs=log_content_box,
        )
        refresh_button.click(
            fn=refresh_log_files,
            outputs=log_file_dropdown,
        )
    
    demo.launch()