From c51f197b6c64c82b880303717c2f98d547d07109 Mon Sep 17 00:00:00 2001
From: lvliang-intel <liang1.lv@intel.com>
Date: Thu, 8 Aug 2024 00:07:05 +0800
Subject: [PATCH 1/3] Add VisualQnA docker for both Gaudi and Xeon

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
---
 VisualQnA/README.md                 |  83 +++++++------
 VisualQnA/docker/Dockerfile         |  33 +++++
 VisualQnA/docker/gaudi/README.md    | 143 ++++++++++++++++++++++
 VisualQnA/docker/gaudi/compose.yaml |  77 ++++++++++++
 VisualQnA/docker/gaudi/set_env.sh   |  11 ++
 VisualQnA/docker/visualqna.py       |  35 ++++++
 VisualQnA/docker/xeon/README.md     | 181 ++++++++++++++++++++++++++++
 VisualQnA/docker/xeon/compose.yaml  |  72 +++++++++++
 VisualQnA/docker/xeon/set_env.sh    |  12 ++
 9 files changed, 609 insertions(+), 38 deletions(-)
 create mode 100644 VisualQnA/docker/Dockerfile
 create mode 100644 VisualQnA/docker/gaudi/README.md
 create mode 100644 VisualQnA/docker/gaudi/compose.yaml
 create mode 100644 VisualQnA/docker/gaudi/set_env.sh
 create mode 100644 VisualQnA/docker/visualqna.py
 create mode 100644 VisualQnA/docker/xeon/README.md
 create mode 100644 VisualQnA/docker/xeon/compose.yaml
 create mode 100644 VisualQnA/docker/xeon/set_env.sh

diff --git a/VisualQnA/README.md b/VisualQnA/README.md
index c00b0d0812..0e4f7f46a2 100644
--- a/VisualQnA/README.md
+++ b/VisualQnA/README.md
@@ -18,61 +18,68 @@ This example guides you through how to deploy a [LLaVA](https://llava-vl.github.
 ![llava screenshot](./assets/img/llava_screenshot1.png)
 ![llava-screenshot](./assets/img/llava_screenshot2.png)
 
-## Start the LLaVA service
+# Deploy VisualQnA Service
 
-1. Build the Docker image needed for starting the service
+The VisualQnA service can be effortlessly deployed on either Intel Gaudi2 or Intel XEON Scalable Processors.
 
-```
-cd serving/
-docker build . --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${http_proxy} -t intel/gen-ai-examples:llava-gaudi
-```
+Currently we support deploying VisualQnA services with docker compose.
 
-2. Start the LLaVA service on Intel Gaudi2
+## Setup Environment Variable
 
-```
-docker run -d -p 8085:8000 -v ./data:/root/.cache/huggingface/hub/ -e http_proxy=$http_proxy -e https_proxy=$http_proxy --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host intel/gen-ai-examples:llava-gaudi
-```
+To set up environment variables for deploying VisualQnA services, follow these steps:
 
-Here are some explanation about the above parameters:
+1. Set the required environment variables:
 
-- `-p 8085:8000`: This will map the 8000 port of the LLaVA service inside the container to the 8085 port on the host
-- `-v ./data:/root/.cache/huggingface/hub/`: This is to prevent from re-downloading model files
-- `http_proxy` and `https_proxy` are used if you have some proxy setting
-- `--runtime=habana ...` is required for running this service on Intel Gaudi2
+   ```bash
+   # Example: host_ip="192.168.1.1"
+   export host_ip="External_Public_IP"
+   # Example: no_proxy="localhost, 127.0.0.1, 192.168.1.1"
+   export no_proxy="Your_No_Proxy"
+   ```
 
-Now you have a LLaVa service with the exposed port `8085` and you can check whether this service is up by:
+2. If you are in a proxy environment, also set the proxy-related environment variables:
 
-```
-curl localhost:8085/health -v
-```
+   ```bash
+   export http_proxy="Your_HTTP_Proxy"
+   export https_proxy="Your_HTTPs_Proxy"
+   ```
 
-If the reply has a `200 OK`, then the service is up.
+3. Set up other environment variables:
 
-## Start the Gradio app
+   > Notice that you can only choose **one** command below to set up envs according to your hardware. Other that the port numbers may be set incorrectly.
 
-Now you have two options to start the frontend UI by following commands:
+   ```bash
+   # on Gaudi
+   source ./docker/gaudi/set_env.sh
+   # on Xeon
+   source ./docker/xeon/set_env.sh
+   ```
 
-### English Interface (Default)
+## Deploy VisualQnA on Gaudi
 
-```
-cd ui/
-pip install -r requirements.txt
-http_proxy= python app.py --host 0.0.0.0 --port 7860 --worker-addr http://localhost:8085 --share
-```
+Refer to the [Gaudi Guide](./docker/gaudi/README.md) to build docker images from source.
 
-### Chinese Interface
+Find the corresponding [compose.yaml](./docker/gaudi/compose.yaml).
 
+```bash
+cd GenAIExamples/VisualQnA/docker/gaudi/
+docker compose up -d
 ```
-cd ui/
-pip install -r requirements.txt
-http_proxy= python app.py --host 0.0.0.0 --port 7860 --worker-addr http://localhost:8085 --lang CN --share
+
+> Notice: Currently only the **Habana Driver 1.16.x** is supported for Gaudi.
+
+
+
+## Deploy VisualQnA on Xeon
+
+Refer to the [Xeon Guide](./docker/xeon/README.md) for more instructions on building docker images from source.
+
+Find the corresponding [compose.yaml](./docker/xeon/compose.yaml).
+
+```bash
+cd GenAIExamples/VisualQnA/docker/xeon/
+docker compose up -d
 ```
 
-Here are some explanation about the above parameters:
 
-- `--host`: the host of the gradio app
-- `--port`: the port of the gradio app, by default 7860
-- `--worker-addr`: the LLaVA service IP address. If you setup the service on a different machine, please replace `localhost` to the IP address of your Gaudi2 host machine
-- `--lang`: Specify this parameter to use the Chinese interface. The default UI language is English and can be used without any additional parameter.
 
-SCRIPT USAGE NOTICE:  By downloading and using any script file included with the associated software package (such as files with .bat, .cmd, or .JS extensions, Docker files, or any other type of file that, when executed, automatically downloads and/or installs files onto your system) (the “Script File”), it is your obligation to review the Script File to understand what files (e.g.,  other software, AI models, AI Datasets) the Script File will download to your system (“Downloaded Files”). Furthermore, by downloading and using the Downloaded Files, even if they are installed through a silent install, you agree to any and all terms and conditions associated with such files, including but not limited to, license terms, notices, or disclaimers.
diff --git a/VisualQnA/docker/Dockerfile b/VisualQnA/docker/Dockerfile
new file mode 100644
index 0000000000..a52c4a35c4
--- /dev/null
+++ b/VisualQnA/docker/Dockerfile
@@ -0,0 +1,33 @@
+
+
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+FROM python:3.11-slim
+
+RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
+    libgl1-mesa-glx \
+    libjemalloc-dev \
+    vim \
+    git
+
+RUN useradd -m -s /bin/bash user && \
+    mkdir -p /home/user && \
+    chown -R user /home/user/
+
+WORKDIR /home/user/
+RUN git clone https://github.com/opea-project/GenAIComps.git
+
+WORKDIR /home/user/GenAIComps
+RUN pip install --no-cache-dir --upgrade pip && \
+    pip install --no-cache-dir -r /home/user/GenAIComps/requirements.txt
+
+COPY ./visualqna.py /home/user/visualqna.py
+
+ENV PYTHONPATH=$PYTHONPATH:/home/user/GenAIComps
+
+USER user
+
+WORKDIR /home/user
+
+ENTRYPOINT ["python", "visualqna.py"]
diff --git a/VisualQnA/docker/gaudi/README.md b/VisualQnA/docker/gaudi/README.md
new file mode 100644
index 0000000000..e01885427e
--- /dev/null
+++ b/VisualQnA/docker/gaudi/README.md
@@ -0,0 +1,143 @@
+# Build MegaService of VisualQnA on Gaudi
+
+This document outlines the deployment process for a VisualQnA application utilizing the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline on Intel Gaudi server. The steps include Docker image creation, container deployment via Docker Compose, and service execution to integrate microservices such as llm. We will publish the Docker images to Docker Hub, it will simplify the deployment process for this service.
+
+## 🚀 Build Docker Images
+
+First of all, you need to build Docker Images locally. This step can be ignored after the Docker images published to Docker hub.
+
+### 1. Source Code install GenAIComps
+
+```bash
+git clone https://github.com/opea-project/GenAIComps.git
+cd GenAIComps
+```
+
+### 2. Build LLM Image
+
+
+```bash
+docker build --no-cache -t opea/lvm-tgi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/lvms/Dockerfile_tgi .
+```
+
+### 3. Build TGI Gaudi Image
+
+Since TGI Gaudi has not supported llava-next in main branch, we'll need to build it from a PR branch for now.
+
+```bash
+git clone https://github.com/yuanwu2017/tgi-gaudi.git
+cd tgi-gaudi/
+git checkout v2.0.4
+docker build -t opea/llava-tgi:latest .
+cd ../
+```
+
+### 4. Build MegaService Docker Image
+
+To construct the Mega Service, we utilize the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline within the `visuralqna.py` Python script. Build the MegaService Docker image using the command below:
+
+```bash
+git clone https://github.com/opea-project/GenAIExamples.git
+cd GenAIExamples/VisualQnA/docker
+docker build --no-cache -t opea/visualqna:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile .
+cd ../../..
+```
+
+
+### 5. Build UI Docker Image
+
+Build frontend Docker image via below command:
+
+```bash
+cd GenAIExamples/VisualQnA/docker/ui/
+docker build --no-cache -t opea/visualqna-ui:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./docker/Dockerfile .
+cd ../../../..
+```
+
+
+Then run the command `docker images`, you will have the following 4 Docker Images:
+
+1. `opea/llava-tgi:latest`
+2. `opea/lvm-tgi:latest`
+3. `opea/visualqna:latest`
+4. `opea/visualqna-ui:latest`
+
+
+## 🚀 Start MicroServices and MegaService
+
+### Setup Environment Variables
+
+Since the `compose.yaml` will consume some environment variables, you need to setup them in advance as below.
+
+```bash
+export no_proxy=${your_no_proxy}
+export http_proxy=${your_http_proxy}
+export https_proxy=${your_http_proxy}
+export LVM_MODEL_ID="llava-hf/llava-v1.6-mistral-7b-hf"
+export LVM_ENDPOINT="http://${host_ip}:8399"
+export LVM_SERVICE_PORT=9399
+export MEGA_SERVICE_HOST_IP=${host_ip}
+export LVM_SERVICE_HOST_IP=${host_ip}
+export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/visualqna"
+```
+
+Note: Please replace with `host_ip` with you external IP address, do **NOT** use localhost.
+
+### Start all the services Docker Containers
+
+```bash
+cd GenAIExamples/VisualQnA/docker/gaudi/
+```
+
+```bash
+docker compose -f compose.yaml up -d
+```
+
+> **_NOTE:_** Users need at least one Gaudi cards to run the VisualQnA successfully.
+
+### Validate MicroServices and MegaService
+
+Follow the instructions to validate MicroServices.
+
+1. LLM Microservice
+
+```bash
+http_proxy="" curl http://${host_ip}:9399/v1/lvm -XPOST -d '{"image": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mP8/5+hnoEIwDiqkL4KAcT9GO0U4BxoAAAAAElFTkSuQmCC", "prompt":"What is this?"}' -H 'Content-Type: application/json'
+```
+
+2. MegaService
+
+```bash
+curl http://${host_ip}:8888/v1/visualqna -H "Content-Type: application/json" -d '{
+     "messages": [
+      {
+        "role": "user",
+        "content": [
+          {
+            "type": "text",
+            "text": "What'\''s in this image?"
+          },
+          {
+            "type": "image_url",
+            "image_url": {
+              "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
+            }
+          }
+        ]
+      }
+    ],
+    "max_tokens": 300
+    }'
+```
+
+## 🚀 Launch the UI
+
+To access the frontend, open the following URL in your browser: http://{host_ip}:5173. By default, the UI runs on port 5173 internally. If you prefer to use a different host port to access the frontend, you can modify the port mapping in the `compose.yaml` file as shown below:
+
+```yaml
+  visualqna-gaudi-ui-server:
+    image: opea/visualqna-ui:latest
+    ...
+    ports:
+      - "80:5173"
+```
diff --git a/VisualQnA/docker/gaudi/compose.yaml b/VisualQnA/docker/gaudi/compose.yaml
new file mode 100644
index 0000000000..8e28f33e49
--- /dev/null
+++ b/VisualQnA/docker/gaudi/compose.yaml
@@ -0,0 +1,77 @@
+
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+version: "3.8"
+
+services:
+  llava-tgi-service:
+    image: opea/llava-tgi:latest
+    container_name: tgi-llava-gaudi-server
+    ports:
+      - "8399:80"
+    volumes:
+      - "./data:/data"
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      HF_HUB_DISABLE_PROGRESS_BARS: 1
+      HF_HUB_ENABLE_HF_TRANSFER: 0
+      HABANA_VISIBLE_DEVICES: all
+      OMPI_MCA_btl_vader_single_copy_mechanism: none
+    runtime: habana
+    cap_add:
+      - SYS_NICE
+    ipc: host
+    command: --model-id ${LVM_MODEL_ID} --max-input-length 1024 --max-total-tokens 2048
+  lvm-tgi:
+    image: opea/lvm-tgi:latest
+    container_name: lvm-tgi-gaudi-server
+    depends_on:
+      - llava-tgi-service
+    ports:
+      - "9399:9399"
+    ipc: host
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      LVM_ENDPOINT: ${LVM_ENDPOINT}
+      HF_HUB_DISABLE_PROGRESS_BARS: 1
+      HF_HUB_ENABLE_HF_TRANSFER: 0
+    restart: unless-stopped
+  visualqna-gaudi-backend-server:
+    image: opea/visualqna:latest
+    container_name: visualqna-gaudi-backend-server
+    depends_on:
+      - llava-tgi-service
+      - lvm-tgi
+    ports:
+      - "8888:8888"
+    environment:
+      - no_proxy=${no_proxy}
+      - https_proxy=${https_proxy}
+      - http_proxy=${http_proxy}
+      - MEGA_SERVICE_HOST_IP=${MEGA_SERVICE_HOST_IP}
+      - LVM_SERVICE_HOST_IP=${LVM_SERVICE_HOST_IP}
+    ipc: host
+    restart: always
+  visualqna-gaudi-ui-server:
+    image: opea/visualqna-ui:latest
+    container_name: visualqna-gaudi-ui-server
+    depends_on:
+      - visualqna-gaudi-backend-server
+    ports:
+      - "5173:5173"
+    environment:
+      - no_proxy=${no_proxy}
+      - https_proxy=${https_proxy}
+      - http_proxy=${http_proxy}
+      - CHAT_BASE_URL=${BACKEND_SERVICE_ENDPOINT}
+    ipc: host
+    restart: always
+
+networks:
+  default:
+    driver: bridge
diff --git a/VisualQnA/docker/gaudi/set_env.sh b/VisualQnA/docker/gaudi/set_env.sh
new file mode 100644
index 0000000000..e4956f8f7a
--- /dev/null
+++ b/VisualQnA/docker/gaudi/set_env.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+export LVM_MODEL_ID="llava-hf/llava-v1.6-mistral-7b-hf"
+export LVM_ENDPOINT="http://${host_ip}:8399"
+export LVM_SERVICE_PORT=9399
+export MEGA_SERVICE_HOST_IP=${host_ip}
+export LVM_SERVICE_HOST_IP=${host_ip}
+export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/visualqna"
\ No newline at end of file
diff --git a/VisualQnA/docker/visualqna.py b/VisualQnA/docker/visualqna.py
new file mode 100644
index 0000000000..b9384ea146
--- /dev/null
+++ b/VisualQnA/docker/visualqna.py
@@ -0,0 +1,35 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+import os
+
+from comps import VisualQnAGateway, MicroService, ServiceOrchestrator, ServiceType
+
+MEGA_SERVICE_HOST_IP = os.getenv("MEGA_SERVICE_HOST_IP", "0.0.0.0")
+MEGA_SERVICE_PORT = int(os.getenv("MEGA_SERVICE_PORT", 8888))
+LVM_SERVICE_HOST_IP = os.getenv("LVM_SERVICE_HOST_IP", "0.0.0.0")
+LVM_SERVICE_PORT = int(os.getenv("LLM_SERVICE_PORT", 9399))
+
+
+class VisualQnAService:
+    def __init__(self, host="0.0.0.0", port=8000):
+        self.host = host
+        self.port = port
+        self.megaservice = ServiceOrchestrator()
+
+    def add_remote_service(self):
+        llm = MicroService(
+            name="llm",
+            host=LVM_SERVICE_HOST_IP,
+            port=LVM_SERVICE_PORT,
+            endpoint="/v1/lvm",
+            use_remote_service=True,
+            service_type=ServiceType.LLM,
+        )
+        self.megaservice.add(llm)
+        self.gateway = VisualQnAGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)
+
+
+if __name__ == "__main__":
+    visualqna = VisualQnAService(host=MEGA_SERVICE_HOST_IP, port=MEGA_SERVICE_PORT)
+    visualqna.add_remote_service()
diff --git a/VisualQnA/docker/xeon/README.md b/VisualQnA/docker/xeon/README.md
new file mode 100644
index 0000000000..2072166544
--- /dev/null
+++ b/VisualQnA/docker/xeon/README.md
@@ -0,0 +1,181 @@
+# Build Mega Service of VisualQnA on Xeon
+
+This document outlines the deployment process for a VisualQnA application utilizing the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline on Intel Xeon server. The steps include Docker image creation, container deployment via Docker Compose, and service execution to integrate microservices such as `llm`. We will publish the Docker images to Docker Hub soon, it will simplify the deployment process for this service.
+
+## 🚀 Apply Xeon Server on AWS
+
+To apply a Xeon server on AWS, start by creating an AWS account if you don't have one already. Then, head to the [EC2 Console](https://console.aws.amazon.com/ec2/v2/home) to begin the process. Within the EC2 service, select the Amazon EC2 M7i or M7i-flex instance type to leverage the power of 4th Generation Intel Xeon Scalable processors. These instances are optimized for high-performance computing and demanding workloads.
+
+For detailed information about these instance types, you can refer to this [link](https://aws.amazon.com/ec2/instance-types/m7i/). Once you've chosen the appropriate instance type, proceed with configuring your instance settings, including network configurations, security groups, and storage options.
+
+After launching your instance, you can connect to it using SSH (for Linux instances) or Remote Desktop Protocol (RDP) (for Windows instances). From there, you'll have full access to your Xeon server, allowing you to install, configure, and manage your applications as needed.
+
+**Certain ports in the EC2 instance need to opened up in the security group, for the microservices to work with the curl commands**
+
+> See one example below. Please open up these ports in the EC2 instance based on the IP addresses you want to allow
+
+```
+llava-tgi-service
+===========
+Port 8399 - Open to 0.0.0.0/0
+
+llm
+===
+Port 9399 - Open to 0.0.0.0/0
+
+visualqna-xeon-backend-server
+==========================
+Port 8888 - Open to 0.0.0.0/0
+
+visualqna-xeon-ui-server
+=====================
+Port 5173 - Open to 0.0.0.0/0
+```
+
+## 🚀 Build Docker Images
+
+First of all, you need to build Docker Images locally and install the python package of it.
+
+```bash
+git clone https://github.com/opea-project/GenAIComps.git
+cd GenAIComps
+```
+
+### 1. Build LVM Image
+
+
+```bash
+docker build --no-cache -t opea/lvm-tgi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/lvms/Dockerfile_tgi .
+```
+
+### 2. Build MegaService Docker Image
+
+To construct the Mega Service, we utilize the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline within the `visualqna.py` Python script. Build MegaService Docker image via below command:
+
+```bash
+git clone https://github.com/opea-project/GenAIExamples.git
+cd GenAIExamples/VisualQnA/docker
+docker build --no-cache -t opea/visualqna:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile .
+cd ../../..
+```
+
+### 3. Build UI Docker Image
+
+Build frontend Docker image via below command:
+
+```bash
+cd GenAIExamples/VisualQnA/docker/ui/
+docker build --no-cache -t opea/visualqna-ui:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./docker/Dockerfile .
+cd ../../../..
+```
+
+### 4. Pull TGI image
+
+```bash
+docker pull ghcr.io/huggingface/text-generation-inference:2.2.0
+```
+
+
+Then run the command `docker images`, you will have the following 4 Docker Images:
+
+1. `ghcr.io/huggingface/text-generation-inference:2.2.0`
+2. `opea/lvm-tgi:latest`
+3. `opea/visualqna:latest`
+4. `opea/visualqna-ui:latest`
+
+
+## 🚀 Start Microservices
+
+### Setup Environment Variables
+
+Since the `compose.yaml` will consume some environment variables, you need to setup them in advance as below.
+
+**Export the value of the public IP address of your Xeon server to the `host_ip` environment variable**
+
+> Change the External_Public_IP below with the actual IPV4 value
+
+```
+export host_ip="External_Public_IP"
+```
+
+**Append the value of the public IP address to the no_proxy list**
+
+```
+export your_no_proxy=${your_no_proxy},"External_Public_IP"
+```
+
+```bash
+export no_proxy=${your_no_proxy}
+export http_proxy=${your_http_proxy}
+export https_proxy=${your_http_proxy}
+export LVM_MODEL_ID="llava-hf/llava-v1.6-mistral-7b-hf"
+export LVM_ENDPOINT="http://${host_ip}:8399"
+export LVM_SERVICE_PORT=9399
+export MEGA_SERVICE_HOST_IP=${host_ip}
+export LVM_SERVICE_HOST_IP=${host_ip}
+export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/visualqna"
+```
+
+Note: Please replace with `host_ip` with you external IP address, do not use localhost.
+
+### Start all the services Docker Containers
+
+> Before running the docker compose command, you need to be in the folder that has the docker compose yaml file
+
+```bash
+cd GenAIExamples/VisualQnA/docker/xeon/
+```
+
+```bash
+docker compose -f compose.yaml up -d
+```
+
+
+### Validate Microservices
+
+
+Follow the instructions to validate MicroServices.
+
+1. LLM Microservice
+
+```bash
+http_proxy="" curl http://${host_ip}:9399/v1/lvm -XPOST -d '{"image": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mP8/5+hnoEIwDiqkL4KAcT9GO0U4BxoAAAAAElFTkSuQmCC", "prompt":"What is this?"}' -H 'Content-Type: application/json'
+```
+
+2. MegaService
+
+```bash
+curl http://${host_ip}:8888/v1/visualqna -H "Content-Type: application/json" -d '{
+     "messages": [
+      {
+        "role": "user",
+        "content": [
+          {
+            "type": "text",
+            "text": "What'\''s in this image?"
+          },
+          {
+            "type": "image_url",
+            "image_url": {
+              "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
+            }
+          }
+        ]
+      }
+    ],
+    "max_tokens": 300
+    }'
+```
+
+
+## 🚀 Launch the UI
+
+To access the frontend, open the following URL in your browser: http://{host_ip}:5173. By default, the UI runs on port 5173 internally. If you prefer to use a different host port to access the frontend, you can modify the port mapping in the `compose.yaml` file as shown below:
+
+```yaml
+  visualqna-gaudi-ui-server:
+    image: opea/visualqna-ui:latest
+    ...
+    ports:
+      - "80:5173"
+```
diff --git a/VisualQnA/docker/xeon/compose.yaml b/VisualQnA/docker/xeon/compose.yaml
new file mode 100644
index 0000000000..9b95012423
--- /dev/null
+++ b/VisualQnA/docker/xeon/compose.yaml
@@ -0,0 +1,72 @@
+
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+version: "3.8"
+
+services:
+  llava-tgi-service:
+    image: ghcr.io/huggingface/text-generation-inference:2.2.0
+    container_name: tgi-llava-xeon-server
+    ports:
+      - "9399:80"
+    volumes:
+      - "./data:/data"
+    shm_size: 1g
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      HF_HUB_DISABLE_PROGRESS_BARS: 1
+      HF_HUB_ENABLE_HF_TRANSFER: 0
+    command: --model-id ${LVM_MODEL_ID}
+  lvm-tgi:
+    image: opea/lvm-tgi:latest
+    container_name: lvm-tgi-server
+    depends_on:
+      - llava-tgi-service
+    ports:
+      - "9399:9399"
+    ipc: host
+    environment:
+      no_proxy: ${no_proxy}
+      http_proxy: ${http_proxy}
+      https_proxy: ${https_proxy}
+      LVM_ENDPOINT: ${LVM_ENDPOINT}
+      HF_HUB_DISABLE_PROGRESS_BARS: 1
+      HF_HUB_ENABLE_HF_TRANSFER: 0
+    restart: unless-stopped
+  visualqna-xeon-backend-server:
+    image: opea/visualqna:latest
+    container_name: visualqna-xeon-backend-server
+    depends_on:
+      - llava-tgi-service
+      - lvm-tgi
+    ports:
+      - "8888:8888"
+    environment:
+      - no_proxy=${no_proxy}
+      - https_proxy=${https_proxy}
+      - http_proxy=${http_proxy}
+      - MEGA_SERVICE_HOST_IP=${MEGA_SERVICE_HOST_IP}
+      - LVM_SERVICE_HOST_IP=${LVM_SERVICE_HOST_IP}
+    ipc: host
+    restart: always
+  visualqna-xeon-ui-server:
+    image: opea/visualqna-ui:latest
+    container_name: visualqna-xeon-ui-server
+    depends_on:
+      - visualqna-xeon-backend-server
+    ports:
+      - "5173:5173"
+    environment:
+      - no_proxy=${no_proxy}
+      - https_proxy=${https_proxy}
+      - http_proxy=${http_proxy}
+      - CHAT_BASE_URL=${BACKEND_SERVICE_ENDPOINT}
+    ipc: host
+    restart: always
+
+networks:
+  default:
+    driver: bridge
diff --git a/VisualQnA/docker/xeon/set_env.sh b/VisualQnA/docker/xeon/set_env.sh
new file mode 100644
index 0000000000..44ca0bc3b6
--- /dev/null
+++ b/VisualQnA/docker/xeon/set_env.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+
+export LVM_MODEL_ID="llava-hf/llava-v1.6-mistral-7b-hf"
+export LVM_ENDPOINT="http://${host_ip}:8399"
+export LVM_SERVICE_PORT=9399
+export MEGA_SERVICE_HOST_IP=${host_ip}
+export LVM_SERVICE_HOST_IP=${host_ip}
+export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/visualqna"

From 5672880b7bdaa858b8d2fd91517a2d8104562339 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Wed, 7 Aug 2024 16:12:07 +0000
Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 VisualQnA/README.md               | 5 -----
 VisualQnA/docker/gaudi/README.md  | 4 ----
 VisualQnA/docker/gaudi/set_env.sh | 2 +-
 VisualQnA/docker/visualqna.py     | 2 +-
 VisualQnA/docker/xeon/README.md   | 6 ------
 5 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/VisualQnA/README.md b/VisualQnA/README.md
index 0e4f7f46a2..757a2657c8 100644
--- a/VisualQnA/README.md
+++ b/VisualQnA/README.md
@@ -68,8 +68,6 @@ docker compose up -d
 
 > Notice: Currently only the **Habana Driver 1.16.x** is supported for Gaudi.
 
-
-
 ## Deploy VisualQnA on Xeon
 
 Refer to the [Xeon Guide](./docker/xeon/README.md) for more instructions on building docker images from source.
@@ -80,6 +78,3 @@ Find the corresponding [compose.yaml](./docker/xeon/compose.yaml).
 cd GenAIExamples/VisualQnA/docker/xeon/
 docker compose up -d
 ```
-
-
-
diff --git a/VisualQnA/docker/gaudi/README.md b/VisualQnA/docker/gaudi/README.md
index e01885427e..aa12c08207 100644
--- a/VisualQnA/docker/gaudi/README.md
+++ b/VisualQnA/docker/gaudi/README.md
@@ -15,7 +15,6 @@ cd GenAIComps
 
 ### 2. Build LLM Image
 
-
 ```bash
 docker build --no-cache -t opea/lvm-tgi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/lvms/Dockerfile_tgi .
 ```
@@ -43,7 +42,6 @@ docker build --no-cache -t opea/visualqna:latest --build-arg https_proxy=$https_
 cd ../../..
 ```
 
-
 ### 5. Build UI Docker Image
 
 Build frontend Docker image via below command:
@@ -54,7 +52,6 @@ docker build --no-cache -t opea/visualqna-ui:latest --build-arg https_proxy=$htt
 cd ../../../..
 ```
 
-
 Then run the command `docker images`, you will have the following 4 Docker Images:
 
 1. `opea/llava-tgi:latest`
@@ -62,7 +59,6 @@ Then run the command `docker images`, you will have the following 4 Docker Image
 3. `opea/visualqna:latest`
 4. `opea/visualqna-ui:latest`
 
-
 ## 🚀 Start MicroServices and MegaService
 
 ### Setup Environment Variables
diff --git a/VisualQnA/docker/gaudi/set_env.sh b/VisualQnA/docker/gaudi/set_env.sh
index e4956f8f7a..f9cd92cc69 100644
--- a/VisualQnA/docker/gaudi/set_env.sh
+++ b/VisualQnA/docker/gaudi/set_env.sh
@@ -8,4 +8,4 @@ export LVM_ENDPOINT="http://${host_ip}:8399"
 export LVM_SERVICE_PORT=9399
 export MEGA_SERVICE_HOST_IP=${host_ip}
 export LVM_SERVICE_HOST_IP=${host_ip}
-export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/visualqna"
\ No newline at end of file
+export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/visualqna"
diff --git a/VisualQnA/docker/visualqna.py b/VisualQnA/docker/visualqna.py
index b9384ea146..eccf720c65 100644
--- a/VisualQnA/docker/visualqna.py
+++ b/VisualQnA/docker/visualqna.py
@@ -3,7 +3,7 @@
 
 import os
 
-from comps import VisualQnAGateway, MicroService, ServiceOrchestrator, ServiceType
+from comps import MicroService, ServiceOrchestrator, ServiceType, VisualQnAGateway
 
 MEGA_SERVICE_HOST_IP = os.getenv("MEGA_SERVICE_HOST_IP", "0.0.0.0")
 MEGA_SERVICE_PORT = int(os.getenv("MEGA_SERVICE_PORT", 8888))
diff --git a/VisualQnA/docker/xeon/README.md b/VisualQnA/docker/xeon/README.md
index 2072166544..225bb9639a 100644
--- a/VisualQnA/docker/xeon/README.md
+++ b/VisualQnA/docker/xeon/README.md
@@ -43,7 +43,6 @@ cd GenAIComps
 
 ### 1. Build LVM Image
 
-
 ```bash
 docker build --no-cache -t opea/lvm-tgi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/lvms/Dockerfile_tgi .
 ```
@@ -75,7 +74,6 @@ cd ../../../..
 docker pull ghcr.io/huggingface/text-generation-inference:2.2.0
 ```
 
-
 Then run the command `docker images`, you will have the following 4 Docker Images:
 
 1. `ghcr.io/huggingface/text-generation-inference:2.2.0`
@@ -83,7 +81,6 @@ Then run the command `docker images`, you will have the following 4 Docker Image
 3. `opea/visualqna:latest`
 4. `opea/visualqna-ui:latest`
 
-
 ## 🚀 Start Microservices
 
 ### Setup Environment Variables
@@ -130,10 +127,8 @@ cd GenAIExamples/VisualQnA/docker/xeon/
 docker compose -f compose.yaml up -d
 ```
 
-
 ### Validate Microservices
 
-
 Follow the instructions to validate MicroServices.
 
 1. LLM Microservice
@@ -167,7 +162,6 @@ curl http://${host_ip}:8888/v1/visualqna -H "Content-Type: application/json" -d
     }'
 ```
 
-
 ## 🚀 Launch the UI
 
 To access the frontend, open the following URL in your browser: http://{host_ip}:5173. By default, the UI runs on port 5173 internally. If you prefer to use a different host port to access the frontend, you can modify the port mapping in the `compose.yaml` file as shown below:

From cdbc0d6fcc9afe1d4ac2411ce2999ad674c6aa45 Mon Sep 17 00:00:00 2001
From: lvliang-intel <liang1.lv@intel.com>
Date: Thu, 8 Aug 2024 23:05:20 +0800
Subject: [PATCH 3/3] update token length

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
---
 VisualQnA/docker/gaudi/compose.yaml | 2 +-
 VisualQnA/docker/visualqna.py       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/VisualQnA/docker/gaudi/compose.yaml b/VisualQnA/docker/gaudi/compose.yaml
index 8e28f33e49..98445056e3 100644
--- a/VisualQnA/docker/gaudi/compose.yaml
+++ b/VisualQnA/docker/gaudi/compose.yaml
@@ -24,7 +24,7 @@ services:
     cap_add:
       - SYS_NICE
     ipc: host
-    command: --model-id ${LVM_MODEL_ID} --max-input-length 1024 --max-total-tokens 2048
+    command: --model-id ${LVM_MODEL_ID} --max-input-length 4096 --max-total-tokens 8192
   lvm-tgi:
     image: opea/lvm-tgi:latest
     container_name: lvm-tgi-gaudi-server
diff --git a/VisualQnA/docker/visualqna.py b/VisualQnA/docker/visualqna.py
index b9384ea146..3492f94ab3 100644
--- a/VisualQnA/docker/visualqna.py
+++ b/VisualQnA/docker/visualqna.py
@@ -19,12 +19,12 @@ def __init__(self, host="0.0.0.0", port=8000):
 
     def add_remote_service(self):
         llm = MicroService(
-            name="llm",
+            name="lvm",
             host=LVM_SERVICE_HOST_IP,
             port=LVM_SERVICE_PORT,
             endpoint="/v1/lvm",
             use_remote_service=True,
-            service_type=ServiceType.LLM,
+            service_type=ServiceType.LVM,
         )
         self.megaservice.add(llm)
         self.gateway = VisualQnAGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)
