Spaces:
Build error
Build error
pr_3_add_button_readme_and_better_logs (#3)
Browse files- Adding better readme (6a9c17dcb2c0970fff46a5f1fba87c2d4e1bd848)
- Adding execute button (80a20422e63f5db2430aa8780d08df11bd7402bf)
- Adding better logs (b2a9c221b75f4c63c7e74c5c56eb81aba74b93d2)
- Adding better exception handling (8bd884a7f207ef9cec1c613edc89a9ff1725c843)
- Adding reverse order (d38510d004f1574318e214adbc143776a71309d0)
- Restructuring and adding download button (f59a2e9cf0439a833071d6f47dfdce948d2087de)
- Ignore logfile (b149c0db43c5eba0158f0c392efea52e40b2d8c3)
Co-authored-by: Derek Thomas <derek-thomas@users.noreply.huggingface.co>
Files changed (6)
11 unmodified lines12131411 unmodified lineseval-queue-bk/eval-results-bk/logs/11 unmodified lines1213141511 unmodified lineseval-queue-bk/eval-results-bk/logs/output.log
1234567891011121314151617181920212223242526import loggingimport sysimport gradio as grfrom main_backend_lighteval import run_auto_evalfrom src.display.log_visualizer import log_file_to_html_stringfrom src.display.css_html_js import dark_mode_gradio_jsfrom src.envs import REFRESH_RATElogging.basicConfig(level=logging.INFO)intro_md = f"""# IntroThis is just a visual for the auto evaluator. Note that the lines of the log visual are reversed.# Logs"""with gr.Blocks(js=dark_mode_gradio_js) as demo:with gr.Tab("Application"):gr.Markdown(intro_md)output = gr.HTML(log_file_to_html_string, every=10)dummy = gr.Markdown(run_auto_eval, every=REFRESH_RATE, visible=False)if __name__ == '__main__':demo.queue(default_concurrency_limit=40).launch(server_name="0.0.0.0", show_error=True, server_port=7860)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import loggingfrom src.logging import configure_root_loggerlogging.getLogger("httpx").setLevel(logging.WARNING)logging.getLogger("numexpr").setLevel(logging.WARNING)logging.getLogger("absl").setLevel(logging.WARNING)configure_root_logger()from functools import partialimport gradio as grfrom main_backend_lighteval import run_auto_evalfrom src.display.log_visualizer import log_file_to_html_stringfrom src.display.css_html_js import dark_mode_gradio_jsfrom src.envs import REFRESH_RATE, REPO_ID, QUEUE_REPO, RESULTS_REPOfrom src.logging import setup_logger, log_filelogging.basicConfig(level=logging.INFO)logger = setup_logger(__name__)intro_md = f"""# IntroThis is a visual for the auto evaluator."""links_md = f"""# Important links| Description | Link ||-----------------|------|| Leaderboard | [{REPO_ID}](https://huggingface.co/spaces/{REPO_ID}) || Queue Repo | [{QUEUE_REPO}](https://huggingface.co/datasets/{QUEUE_REPO}) || Results Repo | [{RESULTS_REPO}](https://huggingface.co/datasets/{RESULTS_REPO}) |"""def button_auto_eval():logger.info("Manually triggering Auto Eval")run_auto_eval()reverse_order_checkbox = gr.Checkbox(label="Reverse Order", value=True)with gr.Blocks(js=dark_mode_gradio_js) as demo:gr.Markdown(intro_md)with gr.Tab("Application"):output_html = gr.HTML(partial(log_file_to_html_string, reverse=reverse_order_checkbox), every=1)with gr.Row():download_button = gr.DownloadButton("Download Log File", value=log_file)with gr.Accordion('Log View Configuration', open=False):reverse_order_checkbox.render()# Add a button that when pressed, triggers run_auto_evalbutton = gr.Button("Manually Run Evaluation")gr.Markdown(links_md)dummy = gr.Markdown(run_auto_eval, every=REFRESH_RATE, visible=False)button.click(fn=button_auto_eval, inputs=[], outputs=[])if __name__ == '__main__':demo.queue(default_concurrency_limit=40).launch(server_name="0.0.0.0", show_error=True, server_port=7860)
69 unmodified lines7071727374758 unmodified lines84858687888969 unmodified lines# instance_size, instance_type = "small", "g4dn.xlarge"# For CPUinstance_size, instance_type = "medium", "c6i"run_evaluation(eval_request=eval_request,8 unmodified lineslimit=LIMIT)if __name__ == "__main__":run_auto_eval()69 unmodified lines707172737475768 unmodified lines858687888990919269 unmodified lines# instance_size, instance_type = "small", "g4dn.xlarge"# For CPUinstance_size, instance_type = "medium", "c6i"logger.info(f'Starting Evaluation of {eval_request.json_filepath} on Inference endpoints: {instance_size} {instance_type}')run_evaluation(eval_request=eval_request,8 unmodified lineslimit=LIMIT)logger.info(f'Completed Evaluation of {eval_request.json_filepath} on Inference endpoints: {instance_size} {instance_type}')if __name__ == "__main__":run_auto_eval()
60 unmodified lines6162636465666760 unmodified linesdumped = json.dumps(results, indent=2)logger.info(dumped)except Exception: # if eval failed, we force a cleanupenv_config = EnvConfig(token=TOKEN, cache_dir=args.cache_dir)model_config = create_model_config(args=args, accelerator=accelerator)60 unmodified lines6162636465666760 unmodified linesdumped = json.dumps(results, indent=2)logger.info(dumped)except Exception as e: # if eval failed, we force a cleanupenv_config = EnvConfig(token=TOKEN, cache_dir=args.cache_dir)model_config = create_model_config(args=args, accelerator=accelerator)
8 unmodified lines91011121314151617181920212223242526272 unmodified lines303132333435368 unmodified linesfrom src.envs import NUM_LINES_VISUALIZEfrom src.logging import log_fileproj_dir = Path(__name__).parentdef log_file_to_html_string():with open(log_file, "rt") as f:# Seek to the end of the file minus 300 lines# Read the last 300 lines of the filelines = f.readlines()lines = lines[-NUM_LINES_VISUALIZE:]# Syntax-highlight the last 300 lines of the file using the Python lexer and Monokai styleoutput = "".join(reversed(lines))syntax = Syntax(output, "python", theme="monokai", word_wrap=True)console = Console(record=True, width=150, style="#272822", file=StringIO())console.print(syntax)2 unmodified lines# Parse the HTML content using BeautifulSoupsoup = BeautifulSoup(html_content, 'lxml')# Modify the <pre> tagpre_tag = soup.prepre_tag['class'] = 'scrollable'del pre_tag['style']8 unmodified lines9101112131415161718192021222324252 unmodified lines282930313233348 unmodified linesfrom src.envs import NUM_LINES_VISUALIZEfrom src.logging import log_filedef log_file_to_html_string(reverse=True):with open(log_file, "rt") as f:lines = f.readlines()lines = lines[-NUM_LINES_VISUALIZE:]if reverse:lines = reversed(lines)output = "".join(lines)syntax = Syntax(output, "python", theme="monokai", word_wrap=True)console = Console(record=True, width=150, style="#272822", file=StringIO())console.print(syntax)2 unmodified lines# Parse the HTML content using BeautifulSoupsoup = BeautifulSoup(html_content, 'lxml')# Modify the <pre> tag and add custom stylespre_tag = soup.prepre_tag['class'] = 'scrollable'del pre_tag['style']
22 unmodified lines232425262728293031323334353637383940414243444546474849505152535422 unmodified linesreturn logger# class Logger:# def __init__(self):# self.terminal = sys.stdout# self.log = open(log_file, "a+")## def write(self, message):# self.terminal.write(message)# self.log.write(message)## def flush(self):# self.terminal.flush()# self.log.flush()## def isatty(self):# return False## def read_logs():# sys.stdout.flush()# #API.upload_file(# # path_or_fileobj="output.log",# # path_in_repo="demo-backend.log",# # repo_id="demo-leaderboard-backend/logs",# # repo_type="dataset",# #)## with open(log_file, "r") as f:# return f.read()## LOGGER = Logger()22 unmodified lines2324252627282930313233343536373822 unmodified linesreturn loggerdef configure_root_logger():# Configure the root loggerlogging.basicConfig(level=logging.INFO)root_logger = logging.getLogger()formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')file_handler = logging.FileHandler(log_file)file_handler.setLevel(logging.INFO)file_handler.setFormatter(formatter)root_logger.addHandler(file_handler)
.gitignore+1
app.py+40-6
main_backend_lighteval.py+3
src/backend/run_eval_suite_lighteval.py+1-1
src/display/log_visualizer.py+9-11
src/logging.py+13-29