This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NeuralChat] Integrate photoai backend into restful API (#478)
- Loading branch information
Showing
19 changed files
with
1,702 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
intel_extension_for_transformers/neural_chat/examples/photo_ai/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Welcome to Photo AI! This example introduces how to deploy the Text Chatbot system and guides you through setting up both the backend and frontend components. You can deploy this chatbot on various platforms, including Intel XEON Scalable Processors, Habana's Gaudi processors (HPU), Intel Data Center GPU and Client GPU, Nvidia Data Center GPU and Client GPU. | ||
|
||
| Section | Link | | ||
| ---------------------| --------------------------| | ||
| Backend Setup | [Backend README](./backend/README.md) | | ||
| Frontend Setup | [Frontend README](./frontend/README.md) | | ||
|
||
|
99 changes: 99 additions & 0 deletions
99
intel_extension_for_transformers/neural_chat/examples/photo_ai/backend/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
This README is intended to guide you through setting up the backend for a Photo AI demo using the NeuralChat framework. You can deploy it on various platforms, including Intel XEON Scalable Processors, Habana's Gaudi processors (HPU), Intel Data Center GPU and Client GPU, Nvidia Data Center GPU and Client GPU. | ||
|
||
|
||
# Setup Environment | ||
|
||
|
||
## Setup Conda | ||
|
||
First, you need to install and configure the Conda environment: | ||
|
||
```shell | ||
# Download and install Miniconda | ||
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | ||
bash `Miniconda*.sh` | ||
source ~/.bashrc | ||
``` | ||
|
||
## Install numactl | ||
|
||
Next, install the numactl library: | ||
|
||
```shell | ||
sudo apt install numactl | ||
``` | ||
|
||
## Install Python dependencies | ||
|
||
Install the following Python dependencies using Conda: | ||
|
||
```shell | ||
conda install astunparse ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses -y | ||
conda install jemalloc gperftools -c conda-forge -y | ||
conda install git-lfs -y | ||
# install libGL.so.1 for opencv | ||
sudo apt-get update | ||
sudo apt-get install -y libgl1-mesa-glx | ||
``` | ||
|
||
Install other dependencies using pip: | ||
|
||
```bash | ||
pip install -r ../../../requirements.txt | ||
``` | ||
|
||
## Install Models | ||
```shell | ||
git-lfs install | ||
# download llama-2 model for NER plugin | ||
git clone https://huggingface.co/meta-llama/Llama-2-7b-chat-hf | ||
# download spacy model for NER post process | ||
python -m spacy download en_core_web_lg | ||
``` | ||
|
||
|
||
# Setup Database | ||
## Install MySQL | ||
```shell | ||
# install mysql | ||
sudo apt-get install mysql-server | ||
# start mysql server | ||
systemctl status mysql | ||
``` | ||
|
||
## Create Tables | ||
```shell | ||
cd ../../../utils/database/ | ||
# login mysql | ||
mysql | ||
source ./init_db_ai_photos.sql | ||
``` | ||
|
||
## Create Image Database | ||
```shell | ||
mkdir /home/nfs_images | ||
export IMAGE_SERVER_IP="your.server.ip" | ||
``` | ||
|
||
# Configurate photoai.yaml | ||
|
||
You can customize the configuration file 'photoai.yaml' to match your environment setup. Here's a table to help you understand the configurable options: | ||
|
||
| Item | Value | | ||
| ------------------- | ---------------------------------------| | ||
| host | 127.0.0.1 | | ||
| port | 9000 | | ||
| model_name_or_path | "./Llama-2-7b-chat-hf" | | ||
| device | "auto" | | ||
| asr.enable | true | | ||
| tts.enable | true | | ||
| ner.enable | true | | ||
| tasks_list | ['voicechat', 'photoai'] | | ||
|
||
|
||
# Run the PhotoAI server | ||
To start the PhotoAI server, use the following command: | ||
|
||
```shell | ||
nohup bash run.sh & | ||
``` |
29 changes: 29 additions & 0 deletions
29
intel_extension_for_transformers/neural_chat/examples/photo_ai/backend/photoai.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
from intel_extension_for_transformers.neural_chat import NeuralChatServerExecutor | ||
|
||
def main(): | ||
server_executor = NeuralChatServerExecutor() | ||
server_executor( | ||
config_file="./photoai.yaml", | ||
log_file="./photoai.log") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
53 changes: 53 additions & 0 deletions
53
intel_extension_for_transformers/neural_chat/examples/photo_ai/backend/photoai.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This is the parameter configuration file for NeuralChat Serving. | ||
|
||
################################################################################# | ||
# SERVER SETTING # | ||
################################################################################# | ||
host: 0.0.0.0 | ||
port: 9000 | ||
|
||
model_name_or_path: "meta-llama/Llama-2-7b-chat-hf" | ||
device: "auto" | ||
|
||
asr: | ||
enable: true | ||
args: | ||
device: "cpu" | ||
model_name_or_path: "openai/whisper-small" | ||
bf16: false | ||
|
||
tts: | ||
enable: true | ||
args: | ||
device: "cpu" | ||
voice: "default" | ||
stream_mode: true | ||
output_audio_path: "./output_audio" | ||
|
||
ner: | ||
enable: true | ||
args: | ||
device: "cpu" | ||
model_path: "./Llama-2-7b-chat-hf" | ||
spacy_model: "en_core_web_lg" | ||
bf16: true | ||
|
||
|
||
tasks_list: ['voicechat', 'photoai'] |
38 changes: 38 additions & 0 deletions
38
intel_extension_for_transformers/neural_chat/examples/photo_ai/backend/run.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Kill the exist and re-run | ||
ps -ef |grep 'photoai' |awk '{print $2}' |xargs kill -9 | ||
|
||
# KMP | ||
export KMP_BLOCKTIME=1 | ||
export KMP_SETTINGS=1 | ||
export KMP_AFFINITY=granularity=fine,compact,1,0 | ||
|
||
# OMP | ||
export OMP_NUM_THREADS=56 | ||
export LD_PRELOAD=${CONDA_PREFIX}/lib/libiomp5.so | ||
|
||
# tc malloc | ||
export LD_PRELOAD=${LD_PRELOAD}:${CONDA_PREFIX}/lib/libtcmalloc.so | ||
|
||
# environment variables | ||
export MYSQL_PASSWORD="root" | ||
export MYSQL_HOST="127.0.0.1" | ||
export MYSQL_DB="ai_photos" | ||
|
||
numactl -l -C 0-55 python -m photoai 2>&1 | tee run.log |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,9 @@ tiktoken==0.4.0 | |
lm_eval | ||
accelerate | ||
cchardet | ||
pymysql | ||
deepface | ||
exifread | ||
spacy | ||
neural-compressor==2.3.1 | ||
pymysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,6 @@ torchaudio==2.1.0 | |
spacy | ||
neural-compressor==2.3.1 | ||
pymysql | ||
deepface | ||
exifread | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,8 @@ tiktoken==0.4.0 | |
lm_eval | ||
spacy | ||
neural-compressor==2.3.1 | ||
intel_extension_for_pytorch | ||
pymysql | ||
deepface | ||
exifread | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.