Skip to content

Commit ab78b2f

Browse files
Made Custom AI Assistant fit the kit template (#162)
* Updated dependencies * Added main script * Using llama 3.2 in custom AI assistant * Changed public argument * Fixed chat model returned path * Added log
1 parent a362927 commit ab78b2f

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

ai_ref_kits/custom_ai_assistant/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Now, let's dive into the steps starting with installing Python. We recommend usi
3939

4040
## Installing Prerequisites
4141

42-
This project requires Python 3.8 or higher and a few libraries. If you don't have Python installed on your machine, go to https://www.python.org/downloads/ and download the latest version for your operating system. Follow the prompts to install Python, making sure to check the option to add Python to your PATH environment variable.
42+
This project requires Python 3.10 or higher and a few libraries. If you don't have Python installed on your machine, go to https://www.python.org/downloads/ and download the latest version for your operating system. Follow the prompts to install Python, making sure to check the option to add Python to your PATH environment variable.
4343

4444
Install libraries and tools:
4545

@@ -178,7 +178,7 @@ Execute the `app.py` script with the following command, including all necessary
178178
```shell
179179
python app.py --asr_model_dir path/to/asr_model --chat_model_dir path/to/chat_model
180180
```
181-
Replace `path/to/asr_model` and `path/to/chat_model` with actual paths to your respective models. Add `--public_interface` to make it publicly accessible.
181+
Replace `path/to/asr_model` and `path/to/chat_model` with actual paths to your respective models. Add `--public` to make it publicly accessible.
182182

183183
### Accessing the Web Interface
184184
After running the script, Gradio will provide a local URL, typically `http://127.0.0.1:XXXX`, which you can open in your web browser to start interacting with the assistant. If you configured the application to be accessible publicly, Gradio will also provide a public URL.

ai_ref_kits/custom_ai_assistant/app.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,17 @@ def run(asr_model_dir: Path, chat_model_dir: Path, public_interface: bool = Fals
323323

324324
# create user interface
325325
demo = create_UI(initial_message)
326+
327+
log.info("Demo is ready!")
326328
# launch demo
327329
demo.queue().launch(share=public_interface)
328330

329331

330332
if __name__ == '__main__':
331333
parser = argparse.ArgumentParser()
332334
parser.add_argument('--asr_model_dir', type=str, default="model/distil-whisper-large-v3-FP16", help="Path to the automatic speech recognition model directory")
333-
parser.add_argument('--chat_model_dir', type=str, default="model/llama3.1-8B-INT4", help="Path to the chat model directory")
334-
parser.add_argument('--public_interface', default=False, action="store_true", help="Whether interface should be available publicly")
335+
parser.add_argument('--chat_model_dir', type=str, default="model/llama3.2-3B-INT4", help="Path to the chat model directory")
336+
parser.add_argument('--public', default=False, action="store_true", help="Whether interface should be available publicly")
335337

336338
args = parser.parse_args()
337339
run(Path(args.asr_model_dir), Path(args.chat_model_dir), args.public_interface)

ai_ref_kits/custom_ai_assistant/convert_and_optimize_chat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def convert_chat_model(model_type: str, precision: str, model_dir: Path) -> Path
2121
precision: model precision
2222
model_dir: dir to export model
2323
Returns:
24-
Path to exported model
24+
Path to exported model dir
2525
"""
2626
output_dir = model_dir / model_type
2727
model_name = MODEL_MAPPING[model_type]
@@ -52,13 +52,13 @@ def convert_chat_model(model_type: str, precision: str, model_dir: Path) -> Path
5252
tokenizer = AutoTokenizer.from_pretrained(model_name)
5353
tokenizer.save_pretrained(output_dir)
5454

55-
return Path(output_dir) / "openvino_model.xml"
55+
return Path(output_dir)
5656

5757

5858
if __name__ == "__main__":
5959
parser = argparse.ArgumentParser()
6060
parser.add_argument("--chat_model_type", type=str, choices=["llama3.1-8B", "llama3-8B", "qwen2-7B", "llama3.2-3B"],
61-
default="llama3.1-8B", help="Chat model to be converted")
61+
default="llama3.2-3B", help="Chat model to be converted")
6262
parser.add_argument("--precision", type=str, default="int4", choices=["fp16", "int8", "int4"], help="Model precision")
6363
parser.add_argument("--model_dir", type=str, default="model", help="Directory to place the model in")
6464

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import argparse
2+
from pathlib import Path
3+
4+
import app
5+
import convert_and_optimize_asr as asr
6+
import convert_and_optimize_chat as chat
7+
8+
9+
def main(args):
10+
asr_model_dir = asr.convert_asr_model(args.asr_model_type, args.asr_precision, Path(args.model_dir))
11+
chat_model_dir = chat.convert_chat_model(args.chat_model_type, args.chat_precision, Path(args.model_dir))
12+
13+
app.run(asr_model_dir, chat_model_dir, args.public)
14+
15+
16+
if __name__ == '__main__':
17+
parser = argparse.ArgumentParser()
18+
19+
parser.add_argument("--asr_model_type", type=str, choices=["distil-whisper-large-v3", "belle-distilwhisper-large-v2-zh"],
20+
default="distil-whisper-large-v3", help="Speech recognition model to be converted")
21+
parser.add_argument("--asr_precision", type=str, default="fp16", choices=["fp16", "int8"], help="ASR model precision")
22+
parser.add_argument("--chat_model_type", type=str, choices=["llama3.1-8B", "llama3-8B", "qwen2-7B", "llama3.2-3B"],
23+
default="llama3.2-3B", help="Chat model to be converted")
24+
parser.add_argument("--chat_precision", type=str, default="int4", choices=["fp16", "int8", "int4"], help="Chat model precision")
25+
parser.add_argument("--model_dir", type=str, default="model", help="Directory to place the model in")
26+
parser.add_argument('--public', default=False, action="store_true", help="Whether interface should be available publicly")
27+
28+
main(parser.parse_args())
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
--extra-index-url https://download.pytorch.org/whl/cpu
22

3-
openvino==2024.4.0
4-
optimum-intel==1.19.0
5-
optimum==1.22.0
6-
nncf==2.13.0
3+
openvino==2024.6.0
4+
optimum-intel==1.21.0
5+
optimum==1.23.3
6+
nncf==2.14.1
77

88
# onnx>1.16.1 doesn't work on windows
9-
onnx==1.16.1
9+
onnx==1.16.1; platform_system == "Windows"
10+
onnx==1.17.0; platform_system != "Windows"
1011
onnxruntime==1.17.3
11-
torch==2.4.1
12+
torch==2.5.1
1213

13-
transformers==4.44.2
14+
transformers==4.46.3
1415
librosa==0.10.2
1516

16-
gradio==5.7.1
17+
gradio==5.10.0

0 commit comments

Comments
 (0)