From 5c75071956b84fda8f92a4cedc22ae0d409b9944 Mon Sep 17 00:00:00 2001 From: Abhishek Thakur Date: Tue, 21 Nov 2023 16:08:59 +0100 Subject: [PATCH] add error page --- src/autotrain/app.py | 13 ++++++++++--- templates/error.html | 21 +++++++++++++++++++++ templates/index.html | 4 ++-- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 templates/error.html diff --git a/src/autotrain/app.py b/src/autotrain/app.py index ac0e9a5c34..040318eac8 100644 --- a/src/autotrain/app.py +++ b/src/autotrain/app.py @@ -93,9 +93,9 @@ PARAMS["tabular"] = TabularParams().model_dump() app = FastAPI() -app.mount("/css", StaticFiles(directory="css"), name="css") # Mounting the static directory -app.mount("/static", StaticFiles(directory="static"), name="static") # Mounting the static directory -templates = Jinja2Templates(directory="templates") # Assuming your HTML is in a folder named 'templates' +# app.mount("/css", StaticFiles(directory="css"), name="css") +app.mount("/static", StaticFiles(directory="static"), name="static") +templates = Jinja2Templates(directory="templates") async def get_request_data(request: Request): @@ -128,6 +128,8 @@ async def read_form(request: Request): :param request: :return: """ + if HF_TOKEN is None or HF_USERNAME is None: + return templates.TemplateResponse("error.html", {"request": request}) return templates.TemplateResponse("index.html", {"request": request}) # The form.html is your saved html file @@ -191,6 +193,11 @@ async def handle_form( """ This function is used to handle the form submission """ + + # if HF_TOKEN is None or HF_USERNAME is None, return error + if HF_TOKEN is None or HF_USERNAME is None: + return {"error": "HF_TOKEN or HF_USERNAME not set"} + params = json.loads(params) training_files = [f.file for f in data_files_training if f.filename != ""] validation_files = [f.file for f in data_files_valid if f.filename != ""] if data_files_valid else [] diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000000..07afb3ed67 --- /dev/null +++ b/templates/error.html @@ -0,0 +1,21 @@ + + + + + + + + + +
+
+ AutoTrain +
+
+ +
+

Error

+

Either HF_TOKEN or HF_USERNAME environment variable is not set.

+
+ + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 4d00515b31..be600a9078 100644 --- a/templates/index.html +++ b/templates/index.html @@ -49,7 +49,7 @@
-
+