derek-thomas HF staff commited on
Commit
d38510d
1 Parent(s): 8bd884a

Adding reverse order

Browse files
Files changed (2) hide show
  1. app.py +10 -1
  2. src/display/log_visualizer.py +9 -11
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from src.logging import configure_root_logger
2
  configure_root_logger()
3
 
 
4
  import logging
5
 
6
  import gradio as gr
@@ -33,15 +34,23 @@ def button_auto_eval():
33
  logger.info("Manually triggering Auto Eval")
34
  run_auto_eval()
35
 
 
 
 
36
  with gr.Blocks(js=dark_mode_gradio_js) as demo:
37
  with gr.Tab("Application"):
38
  gr.Markdown(intro_md)
39
- output = gr.HTML(log_file_to_html_string, every=1)
 
 
 
40
  dummy = gr.Markdown(run_auto_eval, every=REFRESH_RATE, visible=False)
41
 
42
  # Add a button that when pressed, triggers run_auto_eval
43
  button = gr.Button("Manually Run Evaluation")
44
  button.click(fn=button_auto_eval, inputs=[], outputs=[])
45
 
 
 
46
  if __name__ == '__main__':
47
  demo.queue(default_concurrency_limit=40).launch(server_name="0.0.0.0", show_error=True, server_port=7860)
 
1
  from src.logging import configure_root_logger
2
  configure_root_logger()
3
 
4
+ from functools import partial
5
  import logging
6
 
7
  import gradio as gr
 
34
  logger.info("Manually triggering Auto Eval")
35
  run_auto_eval()
36
 
37
+
38
+ reverse_order_checkbox = gr.Checkbox(label="Reverse Order", value=True)
39
+
40
  with gr.Blocks(js=dark_mode_gradio_js) as demo:
41
  with gr.Tab("Application"):
42
  gr.Markdown(intro_md)
43
+ output_html = gr.HTML(partial(log_file_to_html_string, reverse=reverse_order_checkbox), every=1)
44
+ with gr.Accordion('Log View Configuration', open=False) as log_view_config:
45
+ reverse_order_checkbox.render()
46
+
47
  dummy = gr.Markdown(run_auto_eval, every=REFRESH_RATE, visible=False)
48
 
49
  # Add a button that when pressed, triggers run_auto_eval
50
  button = gr.Button("Manually Run Evaluation")
51
  button.click(fn=button_auto_eval, inputs=[], outputs=[])
52
 
53
+
54
+
55
  if __name__ == '__main__':
56
  demo.queue(default_concurrency_limit=40).launch(server_name="0.0.0.0", show_error=True, server_port=7860)
src/display/log_visualizer.py CHANGED
@@ -9,19 +9,17 @@ from src.display.css_html_js import style_content
9
  from src.envs import NUM_LINES_VISUALIZE
10
  from src.logging import log_file
11
 
12
- proj_dir = Path(__name__).parent
13
 
14
-
15
- def log_file_to_html_string():
16
  with open(log_file, "rt") as f:
17
- # Seek to the end of the file minus 300 lines
18
- # Read the last 300 lines of the file
19
- lines = f.readlines()
20
- lines = lines[-NUM_LINES_VISUALIZE:]
 
21
 
22
- # Syntax-highlight the last 300 lines of the file using the Python lexer and Monokai style
23
- output = "".join(reversed(lines))
24
- syntax = Syntax(output, "python", theme="monokai", word_wrap=True)
25
 
26
  console = Console(record=True, width=150, style="#272822", file=StringIO())
27
  console.print(syntax)
@@ -30,7 +28,7 @@ def log_file_to_html_string():
30
  # Parse the HTML content using BeautifulSoup
31
  soup = BeautifulSoup(html_content, 'lxml')
32
 
33
- # Modify the <pre> tag
34
  pre_tag = soup.pre
35
  pre_tag['class'] = 'scrollable'
36
  del pre_tag['style']
 
9
  from src.envs import NUM_LINES_VISUALIZE
10
  from src.logging import log_file
11
 
 
12
 
13
+ def log_file_to_html_string(reverse=True):
 
14
  with open(log_file, "rt") as f:
15
+ lines = f.readlines()
16
+ lines = lines[-NUM_LINES_VISUALIZE:]
17
+
18
+ if reverse:
19
+ lines = reversed(lines)
20
 
21
+ output = "".join(lines)
22
+ syntax = Syntax(output, "python", theme="monokai", word_wrap=True)
 
23
 
24
  console = Console(record=True, width=150, style="#272822", file=StringIO())
25
  console.print(syntax)
 
28
  # Parse the HTML content using BeautifulSoup
29
  soup = BeautifulSoup(html_content, 'lxml')
30
 
31
+ # Modify the <pre> tag and add custom styles
32
  pre_tag = soup.pre
33
  pre_tag['class'] = 'scrollable'
34
  del pre_tag['style']