From cde7259ed79a38b7f1474bbfc103f38dfc492bbf Mon Sep 17 00:00:00 2001 From: nicola leonardi Date: Tue, 2 Dec 2025 10:40:55 +0100 Subject: [PATCH] dockercompose management --- README.md | 4 +- .../__pycache__/utils.cpython-310.pyc | Bin 2615 -> 0 bytes UI/wcag_validator_ui.py | 38 ++++++++--------- docker/README.md | 40 ++++++++++++++++++ docker/UI/Dockerfile | 2 +- docker/docker-compose.yml | 33 +++++++++++++++ 6 files changed, 94 insertions(+), 23 deletions(-) delete mode 100644 UI/dependences_ui/__pycache__/utils.cpython-310.pyc create mode 100644 docker/README.md create mode 100644 docker/docker-compose.yml diff --git a/README.md b/README.md index 8d0d842..ec921a1 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,13 @@ python wcag_validator_RESTserver.py ## For UI use: python wcag_validator_ui.py -## Docker +## Docker (file docker placed at path /LLM_accessibility_validator) ### Rest server docker build -t wcag_resr_server . docker run --env-file .env -p 8000:8000 --name wcag_rest_server -d wcag_rest_server ### UI docker build -t wcag_ui . -docker run --env-file UI/.env -p 8001:8001 --name wcag_ui -d wcag_ui +docker run --env-file UI/.env -p 7860:7860 --name wcag_ui -d wcag_ui ## The scripts folder contains some elaboration scripts. They require a dedicated requirements file \ No newline at end of file diff --git a/UI/dependences_ui/__pycache__/utils.cpython-310.pyc b/UI/dependences_ui/__pycache__/utils.cpython-310.pyc deleted file mode 100644 index 30e3cb8267fe6fc253e6f4faabaa11a2afd38687..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2615 zcmb7GO>YxN7@nD3+Z)FTNvH^vrX3?naTU^*svIg>wW1(`f{QQ|5m|NDI}>}!de@y< zC&Y53N@#;dF_R zzs%t1$1wN?MgN3K5J4ldI&A4GwPUu*Z0oGLg01F+BivufYF^|-9&JGsgooA>6QYQA zLQIMh+M<{e(`YBfDKUe#BxsFPW?$kKQtcOeS}MKtL?>}zW=0=H$3wY+qQ66xk|%VR zrOqBzJatn?&>i;s)HX?TyZHgxqmKw9g1N*cI}Rl^@)^ z&D;p0Dm0^O`$SDb#eaXf@nt>mRVt&%Zv;s!!i`Y-^}Bx14r93@eHDjstA2ZVxfc1& zx*r5m>#!L{VY*e1lTJOLeLP8HAV+d&U!g?5S^hf8dlUU;Qu(LH92G0a7=m@&IkvP%bKm+b)`yUw0L0PUZ@?dvx0 z`dV)$%0K}j;kDb}Ub*_kwThb++E|XlW|r4&A5(xq93()J~{)U+yT{j^FRi4z}6jAGJZ`l+M&W(C+Z#H zVoZ0)wuy|hLDYiCVTPF<1I%3~sWWhP0DLh4bBq1c_hkz(mWum4mYX&<6(=M8OAqn# zV!tD~AB(X+0zU>4c~f%P>84xdYQ<5;jQ;$+1D9zo5^nZ%{4{8nt1nGVM!ObAyLhLk ztr$P$k@V5O#)G!6`~bRW9wl*WEc@(Omq2WEoCWqWCz7#!05%d9J(%?j^o$qO8SKku@M_mW z)j5oyn!)smAgcqPT3{|ML;YTb?(dIcGov00D46zP$ti3Br5Mwwah1kUxkh zzHkn;80$W^XWT>P7+O)8?4SN&NN_{?7)G&w`JTZJuoxQzHHgMZ&j$JoBqObY^ig6Fj0qaFYmK#0)S~r(FkMp9%9ln%wfRxNJc?|=h5_o^+od}!6AZjIyH-Lf(^(S$h4UG9Q*YhR35`e87&_C+<)@LlXEl0 z*LM{sF?H;m`Uv7q@S$N`i?UDAG3XKwB1MEduo>0l?gNz3 zQV4=|;;pJGLt6hV*5Ej9*2j-A+A2R#A7H)0)I~JvLsa`zT{3->CXcZDBs_xC)+G{4 zdK#6nb>tBDKUKlh39}Aqo?{gh57Y3+U>dM9ef&uP4BZz_jTm;U@~ diff --git a/UI/wcag_validator_ui.py b/UI/wcag_validator_ui.py index 8cd3f46..edfb8f5 100644 --- a/UI/wcag_validator_ui.py +++ b/UI/wcag_validator_ui.py @@ -31,7 +31,6 @@ import sqlite3 WCAG_VALIDATOR_RESTSERVER_HEADERS = [("Content-Type", "application/json")] - def load_images_from_json(json_input): """Extract URLs and alt text from JSON and create HTML gallery""" try: @@ -225,7 +224,6 @@ def load_llm_assessment_from_json(json_input): data_frame.append( { - "Original Alt Text": alt_text_original, "LLM Assessment": original_alt_text_assessment, "Proposed Alt Text": new_alt_text, @@ -245,13 +243,13 @@ def make_alttext_llm_assessment_api_call( url, selected_images_json=[], db_path=None, - wcga_rest_server_url="http://localhost:8000", + wcag_rest_server_url="http://localhost:8000", user_state={}, number_of_images=30, ): print( - f"Making API call for llm assessment for {url} to {wcga_rest_server_url}/wcag_alttext_validation" + f"Making API call for llm assessment for {url} to {wcag_rest_server_url}/wcag_alttext_validation" ) selected_images = json.loads(selected_images_json) if selected_images_json else [] # print("selected_images:", selected_images) @@ -299,13 +297,13 @@ def make_alttext_llm_assessment_api_call( "save_elaboration": "True", "specific_images_urls": selected_urls, }, - url=wcga_rest_server_url + "/wcag_alttext_validation", + url=wcag_rest_server_url + "/wcag_alttext_validation", headers=WCAG_VALIDATOR_RESTSERVER_HEADERS, ) # return response info_dataframe = load_llm_assessment_from_json(response) info_dataframe.insert( - 0, 'Image #', selected_image_id + 0, "Image #", selected_image_id ) # add the UI ids from to api response except Exception as e: @@ -334,10 +332,10 @@ def make_alttext_llm_assessment_api_call( def make_image_extraction_api_call( url, number_of_images=30, - wcga_rest_server_url="http://localhost:8000", + wcag_rest_server_url="http://localhost:8000", ): print( - f"Making API call for image_extraction for {url} to {wcga_rest_server_url}/extract_images" + f"Making API call for image_extraction for {url} to {wcag_rest_server_url}/extract_images" ) try: @@ -346,7 +344,7 @@ def make_image_extraction_api_call( "page_url": url, "number_of_images": number_of_images, }, - url=wcga_rest_server_url + "/extract_images", + url=wcag_rest_server_url + "/extract_images", headers=WCAG_VALIDATOR_RESTSERVER_HEADERS, ) # return response @@ -369,18 +367,18 @@ with gr.Blocks(theme=gr.themes.Glass(), title="WCAG AI Validator") as demo: _ = load_dotenv(env_path) # read .env file db_path = return_from_env_valid("DB_PATH", "persistence/wcag_validator_ui.db") print("db_path:", db_path) - wcga_rest_server_url = return_from_env_valid( - "WCGA_REST_SERVER_URL", "http://localhost:8000" + wcag_rest_server_url = return_from_env_valid( + "WCAG_REST_SERVER_URL", "http://localhost:8000" ) default_urls = [ - "https://amazon.com", - "https://ebay.com", - ] - url_list_str=return_from_env_valid("URL_LIST",json.dumps(default_urls)) + "https://amazon.com", + "https://ebay.com", + ] + url_list_str = return_from_env_valid("URL_LIST", json.dumps(default_urls)) url_list = json.loads(url_list_str) - print("wcga_rest_server_url:", wcga_rest_server_url) + print("wcag_rest_server_url:", wcag_rest_server_url) connection_db = db_persistence_startup( db_name_and_path=db_path, table="wcag_user_assessments" @@ -434,8 +432,8 @@ with gr.Blocks(theme=gr.themes.Glass(), title="WCAG AI Validator") as demo: with gr.Tab("Alt Text Assessment", visible=False) as alttext_assessment: - db_path_state = gr.State(value=db_path) # Store path in State - wcga_rest_server_url_state = gr.State(value=wcga_rest_server_url) + db_path_state = gr.State(value=db_path) # Store path in State\ + wcag_rest_server_url_state = gr.State(value=wcag_rest_server_url) with gr.Row(): with gr.Column(): @@ -498,7 +496,7 @@ with gr.Blocks(theme=gr.themes.Glass(), title="WCAG AI Validator") as demo: ], ).then( make_image_extraction_api_call, - inputs=[url_input, images_number, wcga_rest_server_url_state], + inputs=[url_input, images_number, wcag_rest_server_url_state], outputs=[image_info_output, gallery_html], ).then( fn=lambda: gr.Button(interactive=True), @@ -514,7 +512,7 @@ with gr.Blocks(theme=gr.themes.Glass(), title="WCAG AI Validator") as demo: url_input, gallery_html, db_path_state, - wcga_rest_server_url_state, + wcag_rest_server_url_state, user_state, ], outputs=[alttext_info_output], diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..f7fe8d4 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,40 @@ +# Create (and eventually run) the two containers + +## Docker +### Rest server +- docker build -t wcag_resr_server . +- docker run --env-file .env -p 8000:8000 --name wcag_rest_server -d wcag_rest_server +### UI +- docker build -t wcag_ui . +- docker run --env-file UI/.env -p 7860:7860 --name wcag_ui -d wcag_ui + + +# For network management and env management +## method 1: Run the docker-compose (skip the runs above) + +docker-compose up -d + +## method 2: or creating a Docker network + +### Create a custom network +docker network create wcag-network + +### Run the backend container +docker run -d \ + --name wcag_rest_server \ + --network wcag-network \ + --env-file .env \ + wcag_rest_server + +# Run the UI container +docker run -d \ + --name wcag_ui \ + --network wcag-network \ + -p 7860:7860 \ + --env-file UI/.env \ + wcag_ui + +# Important Notes: + +- Backend URL in UI: Make sure your UI is configured to connect to the backend using the container name (e.g., wcag_rest_server) not localhost when running in Docker +- Port exposure: Only the UI needs -p flag to expose ports to your host machine \ No newline at end of file diff --git a/docker/UI/Dockerfile b/docker/UI/Dockerfile index 3b64cc2..7d8b0ae 100644 --- a/docker/UI/Dockerfile +++ b/docker/UI/Dockerfile @@ -15,7 +15,7 @@ COPY /UI/wcag_validator_ui.py /UI/wcag_validator_ui.py EXPOSE 7860 WORKDIR /UI -CMD ["python","wcag_validator_ui.py"] +CMD ["python", "-u", "wcag_validator_ui.py"] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..ec294ec --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3.8' + +services: + backend: + image: wcag_rest_server + container_name: wcag_rest_server + ports: + - "8000:8000" # Adjust to your backend port + environment: + - MLLM_END_POINT_OPENAI=https://hiis-accessibility-fonderia.cognitiveservices.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2025-01-01-preview + - MLLM_API_KEY_OPENAI=4lwGUwrx7jsqdxESGBpN9wYYyLNsxzC2s8ZLQlZPCQUayDWuDo3NJQQJ99BKACfhMk5XJ3w3AAAAACOGs2uw + - MLLM_MODEL_ID_OPENAI=gpt-4o + - USE_OPENAI_MODEL=True + networks: + - wcag-network + + ui: + image: wcag_ui + container_name: wcag_ui + ports: + - "7860:7860" # Adjust to your UI port + environment: + - WCAG_REST_SERVER_URL=http://backend:8000 # UI can reference backend by service name + - URL_LIST=["https://amazon.com","https://ebay.com","https://walmart.com","https://etsy.com","https://target.com","https://wayfair.com","https://bestbuy.com","https://macys.com","https://homedepot.com","https://costco.com","https://www.ansa.it","https://en.wikipedia.org/wiki/Main_Page","https://www.lanazione.it","https://www.ansa.it","https://www.bbc.com","https://www.cnn.com","https://www.nytimes.com","https://www.theguardian.com"] + - DB_PATH=persistence/wcag_validator_ui.db + depends_on: + - backend + networks: + - wcag-network + +networks: + wcag-network: + driver: bridge \ No newline at end of file