Skip to content

Commit 251991a

Browse files
Gradio UI for CodeGen (#4)
* update the compose file Signed-off-by: Mustafa <[email protected]> initial Signed-off-by: Mustafa <[email protected]> added microservice ports Signed-off-by: okhleif-IL <[email protected]> update codegen Signed-off-by: Mustafa <[email protected]> update for codegen Signed-off-by: Mustafa <[email protected]> Initial commit for Gradio UI Signed-off-by: okhleif-IL <[email protected]> New UI Signed-off-by: okhleif-IL <[email protected]> prepare for merge Signed-off-by: okhleif-IL <[email protected]> add agents Signed-off-by: Mustafa <[email protected]> env updates Signed-off-by: Mustafa <[email protected]> update codegen Signed-off-by: Mustafa <[email protected]> merged to main Signed-off-by: Mustafa <[email protected]> updates Signed-off-by: Mustafa <[email protected]> UI Updates Signed-off-by: okhleif-IL <[email protected]> added dockerfile Signed-off-by: okhleif-IL <[email protected]> removed files dataframe Signed-off-by: okhleif-IL <[email protected]> updated file upload Signed-off-by: okhleif-IL <[email protected]> added checkbox for agent Signed-off-by: okhleif-IL <[email protected]> key_index_name --> index_name Signed-off-by: okhleif-IL <[email protected]> added / removed print statements Signed-off-by: okhleif-IL <[email protected]> Support for data streaming (from Melanie) Signed-off-by: okhleif-IL <[email protected]> fixed file not supported bug Signed-off-by: okhleif-IL <[email protected]> added refresh button to index Signed-off-by: okhleif-IL <[email protected]> simplified README Signed-off-by: okhleif-IL <[email protected]> * updated readme and fixed merge Signed-off-by: okhleif-IL <[email protected]> * reverted changes Signed-off-by: okhleif-IL <[email protected]> --------- Signed-off-by: okhleif-IL <[email protected]> Co-authored-by: Mustafa <[email protected]>
1 parent f33ba5a commit 251991a

File tree

10 files changed

+563
-9
lines changed

10 files changed

+563
-9
lines changed

CodeGen/Dockerfile

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,51 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
ARG BASE_TAG=latest
5-
FROM opea/comps-base:$BASE_TAG
4+
# Stage 1: base setup used by other stages
5+
FROM python:3.11-slim AS base
6+
7+
# get security updates
8+
RUN apt-get update && apt-get upgrade -y && \
9+
apt-get clean && rm -rf /var/lib/apt/lists/*
10+
11+
ENV HOME=/home/user
12+
13+
RUN useradd -m -s /bin/bash user && \
14+
mkdir -p $HOME && \
15+
chown -R user $HOME
16+
17+
WORKDIR $HOME
18+
19+
20+
# Stage 2: latest GenAIComps sources
21+
FROM base AS git
22+
23+
RUN apt-get update && apt-get install -y --no-install-recommends git
24+
# RUN git clone --depth 1 https://github.com/opea-project/GenAIComps.git
25+
COPY GenAIComps GenAIComps
26+
27+
28+
# Stage 3: common layer shared by services using GenAIComps
29+
FROM base AS comps-base
30+
31+
# copy just relevant parts
32+
COPY --from=git $HOME/GenAIComps/comps $HOME/GenAIComps/comps
33+
COPY --from=git $HOME/GenAIComps/*.* $HOME/GenAIComps/LICENSE $HOME/GenAIComps/
34+
35+
WORKDIR $HOME/GenAIComps
36+
RUN pip install --no-cache-dir --upgrade pip setuptools && \
37+
pip install --no-cache-dir -r $HOME/GenAIComps/requirements.txt
38+
WORKDIR $HOME
39+
40+
ENV PYTHONPATH=$PYTHONPATH:$HOME/GenAIComps
41+
42+
USER user
43+
44+
45+
# Stage 4: unique part
46+
FROM comps-base
47+
48+
ENV LANG=C.UTF-8
649

750
COPY ./codegen.py $HOME/codegen.py
851

CodeGen/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,4 @@ def start(self):
313313
if __name__ == "__main__":
314314
chatqna = CodeGenService(port=MEGA_SERVICE_PORT)
315315
chatqna.add_remote_service()
316-
chatqna.start()
316+
chatqna.start()

CodeGen/docker_compose/intel/cpu/xeon/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,4 @@ Then run the command `docker images`, you will have the following Docker Images:
330330
- `opea/llm-textgen:latest`
331331
- `opea/codegen:latest`
332332
- `opea/codegen-ui:latest`
333-
- `opea/codegen-react-ui:latest` (optional)
333+
- `opea/codegen-react-ui:latest` (optional)

CodeGen/docker_compose/intel/cpu/xeon/compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Copyright (C) 2024 Intel Corporation
2-
# SPDX-License-Identifier: Apache-2.0
3-
41
services:
52

63
tgi-service:
@@ -100,7 +97,7 @@ services:
10097
ipc: host
10198
restart: always
10299
codegen-xeon-ui-server:
103-
image: ${REGISTRY:-opea}/codegen-ui:${TAG:-latest}
100+
image: ${REGISTRY:-opea}/codegen-gradio-ui:${TAG:-latest}
104101
container_name: codegen-xeon-ui-server
105102
depends_on:
106103
- codegen-xeon-backend-server
@@ -111,6 +108,9 @@ services:
111108
- https_proxy=${https_proxy}
112109
- http_proxy=${http_proxy}
113110
- BASIC_URL=${BACKEND_SERVICE_ENDPOINT}
111+
- MEGA_SERVICE_PORT=${MEGA_SERVICE_PORT}
112+
- host_ip=${host_ip}
113+
- DATAPREP_ENDPOINT=${DATAPREP_ENDPOINT}
114114
ipc: host
115115
restart: always
116116
redis-vector-db:

CodeGen/docker_compose/set_env.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ export TEI_EMBEDDING_HOST_IP=${host_ip}
4747
export TEI_EMBEDDING_ENDPOINT="http://${host_ip}:${TEI_EMBEDDER_PORT}"
4848

4949
export DATAPREP_REDIS_PORT=6007
50+
export DATAPREP_ENDPOINT="http://${host_ip}:${DATAPREP_REDIS_PORT}/v1/dataprep"
5051
export LOGFLAG=false
51-
export MODEL_CACHE="./data"
52+
export MODEL_CACHE="./data"

CodeGen/docker_image_build/build.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ services:
2323
dockerfile: ./docker/Dockerfile.react
2424
extends: codegen
2525
image: ${REGISTRY:-opea}/codegen-react-ui:${TAG:-latest}
26+
codegen-gradio-ui:
27+
build:
28+
context: ../ui
29+
dockerfile: ./docker/Dockerfile.gradio
30+
extends: codegen
31+
image: ${REGISTRY:-opea}/codegen-gradio-ui:${TAG:-latest}
2632
llm-textgen:
2733
build:
2834
context: GenAIComps
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
FROM python:3.11-slim
5+
6+
ENV LANG=C.UTF-8
7+
8+
ARG ARCH="cpu"
9+
10+
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
11+
build-essential \
12+
default-jre \
13+
libgl1-mesa-glx \
14+
libjemalloc-dev \
15+
wget
16+
17+
# Install ffmpeg static build
18+
WORKDIR /root
19+
RUN wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz && \
20+
mkdir ffmpeg-git-amd64-static && tar -xvf ffmpeg-git-amd64-static.tar.xz -C ffmpeg-git-amd64-static --strip-components 1 && \
21+
export PATH=/root/ffmpeg-git-amd64-static:$PATH && \
22+
cp /root/ffmpeg-git-amd64-static/ffmpeg /usr/local/bin/ && \
23+
cp /root/ffmpeg-git-amd64-static/ffprobe /usr/local/bin/
24+
25+
RUN mkdir -p /home/user
26+
27+
COPY gradio /home/user/gradio
28+
29+
RUN pip install --no-cache-dir --upgrade pip setuptools && \
30+
pip install --no-cache-dir -r /home/user/gradio/requirements.txt
31+
32+
WORKDIR /home/user/gradio
33+
ENTRYPOINT ["python", "codegen_ui_gradio.py"]

CodeGen/ui/gradio/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Document Summary
2+
3+
This project provides a user interface for summarizing documents and text using a Dockerized frontend application. Users can upload files or paste text to generate summaries.
4+
5+
## Docker
6+
7+
### Build UI Docker Image
8+
9+
To build the frontend Docker image, navigate to the `GenAIExamples/DocSum/ui` directory and run the following command:
10+
11+
```bash
12+
cd GenAIExamples/CodeGen/ui
13+
docker build -t opea/codegen-gradio-ui:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f docker/Dockerfile.gradio .
14+
```
15+
16+
This command builds the Docker image with the tag `opea/codegen-gradio-ui:latest`. It also passes the proxy settings as build arguments to ensure that the build process can access the internet if you are behind a corporate firewall.
17+
18+
### Run UI Docker Image
19+
20+
To run the frontend Docker image, navigate to the `GenAIExamples/CodeGen/ui/gradio` directory and execute the following commands:
21+
22+
```bash
23+
cd GenAIExamples/CodeGen/ui/gradio
24+
25+
ip_address=$(hostname -I | awk '{print $1}')
26+
docker run -d -p 5173:5173 --ipc=host \
27+
-e http_proxy=$http_proxy \
28+
-e https_proxy=$https_proxy \
29+
-e no_proxy=$no_proxy \
30+
-e BACKEND_SERVICE_ENDPOINT=http://$ip_address:7778/v1/codegen \
31+
opea/codegen-gradio-ui:latest
32+
```
33+
34+
This command runs the Docker container in interactive mode, mapping port 5173 of the host to port 5173 of the container. It also sets several environment variables, including the backend service endpoint, which is required for the frontend to communicate with the backend service.
35+
36+
### Python
37+
38+
To run the frontend application directly using Python, navigate to the `GenAIExamples/CodeGen/ui/gradio` directory and run the following command:
39+
40+
```bash
41+
cd GenAIExamples/CodeGen/ui/gradio
42+
python codegen_ui_gradio.py
43+
```
44+
45+
This command starts the frontend application using Python.
46+
47+
## Additional Information
48+
49+
### Prerequisites
50+
51+
Ensure you have Docker installed and running on your system. Also, make sure you have the necessary proxy settings configured if you are behind a corporate firewall.
52+
53+
### Environment Variables
54+
55+
- `http_proxy`: Proxy setting for HTTP connections.
56+
- `https_proxy`: Proxy setting for HTTPS connections.
57+
- `no_proxy`: Comma-separated list of hosts that should be excluded from proxying.
58+
- `BACKEND_SERVICE_ENDPOINT`: The endpoint of the backend service that the frontend will communicate with.
59+
60+
### Troubleshooting
61+
62+
- Docker Build Issues: If you encounter issues while building the Docker image, ensure that your proxy settings are correctly configured and that you have internet access.
63+
- Docker Run Issues: If the Docker container fails to start, check the environment variables and ensure that the backend service is running and accessible.
64+
65+
This README file provides detailed instructions and explanations for building and running the Dockerized frontend application, as well as running it directly using Python. It also highlights the key features of the project and provides additional information for troubleshooting and configuring the environment.

0 commit comments

Comments
 (0)