From afdf77dd4277b585a5ba052d768b58cbd86c3895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?apolin=C3=A1rio?= Date: Fri, 8 Dec 2023 14:13:39 +0100 Subject: [PATCH] create post if training fails --- src/autotrain/utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/autotrain/utils.py b/src/autotrain/utils.py index a3c267acff..4a93ed9db7 100644 --- a/src/autotrain/utils.py +++ b/src/autotrain/utils.py @@ -280,12 +280,16 @@ def wrapper(*args, **kwargs): return func(*args, **kwargs) except Exception: if PartialState().process_index == 0: - logger.error(f"{func.__name__} has failed due to an exception:") - logger.error(traceback.format_exc()) + error_message = f'''{func.__name__} has failed due to an exception: {traceback.format_exc()}''' + logger.error(error_message) if "SPACE_ID" in os.environ: # shut down the space logger.info("Pausing space...") api = HfApi(token=os.environ["HF_TOKEN"]) api.pause_space(repo_id=os.environ["SPACE_ID"]) - + api.create_discussion(repo_id=os.environ['SPACE_ID'], + title="Your training has failed ❌", + description=error_message, + repo_type="space" + ) return wrapper