Skip to content

Commit

Permalink
Merge pull request #177 from Gregory-Pereira/fix-whispercpp-ms-docs-a…
Browse files Browse the repository at this point in the history
…nd-make

update whipser ms scripts and docs
  • Loading branch information
rhatdan authored Apr 7, 2024
2 parents 8a51032 + c32ac8a commit c13d712
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 11 deletions.
62 changes: 56 additions & 6 deletions .github/workflows/model_servers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ on:
pull_request:
branches:
- main
# paths:
# - ./model_servers/llamacpp_python/**
# - .github/workflows/model_servers.yaml
paths:
- ./model_servers/
- .github/workflows/model_servers.yaml
push:
branches:
- main
# paths:
# - ./model_servers/llamacpp_python/**
# - .github/workflows/model_servers.yaml
paths:
- ./model_servers/
- .github/workflows/model_servers.yaml

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/model_servers
# Image Repo Migration variables
NEW_REGISTRY: quay.io
NEW_REGISTRY_USER: ai-lab+ghrobot
NEW_IMAGE_NAME_LLAMA: quay.io/ai-lab/model_servers/llamacpp_python
IMAGE_NAME_WHISPER: quay.io/ai-lab/model_servers/whispercpp


jobs:
build-and-push-image:
Expand Down Expand Up @@ -78,3 +84,47 @@ jobs:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ env.REGISTRY }}
build-and-push-image-whispercpp:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
services:
registry:
image: registry:2.8.3
ports:
- 5000:5000
steps:
- name: Build Image Whispercpp
id: build_image_whisper
uses: redhat-actions/[email protected]
working-directory: ./model_servers/whispercpp/
run: make build

- name: Download model Whispercpp
working-directory: ./model_servers/whispercpp/
run: make download-model-whisper-small

- name: Login to container registry
if: >
(github.event_name == 'push' || github.event_name == 'schedule') &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: docker/[email protected]
with:
registry: ${{ env.NEW_REGISTRY }}
username: ${{ env.NEW_REGISTRY_USER }}
password: ${{ secrets.AILAB_GHROBOT_TOKEN }} # THIS NEEDS TO BE CREATED

- name: Push image
id: push_image
if: >
(github.event_name == 'push' || github.event_name == 'schedule') &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: redhat-actions/[email protected]
with:
image: ${{ steps.build_image_whisper.outputs.image }}
tags: ${{ steps.build_image_whisper.outputs.tags }}
registry: ${{ env.NEW_REGISTRY }}

47 changes: 47 additions & 0 deletions model_servers/whispercpp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
PORT := 8001
APP := whispercpp
IMAGE := quay.io/ai-lab/model_servers/$(APP):latest
CUDA_IMAGE := quay.io/ai-lab/model_servers/$(APP)_cuda:latest
VULKAN_IMAGE :=quay.io/ai-lab/model_servers/$(APP)_vulkan:latest

# ----- MODEL OPTIONS -----

WHISPER_SMALL_MODEL_NAME := ggml-small.bin
WHISPER_SMALL_MODEL_URL := https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin

WHISPER_BASE_MODEL_NAME := ggml-base.en.bin
WHISPER_BASE_MODEL_URL := https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin

SELECTED_MODEL_NAME := $(or $(SELECTED_MODEL),$(WHISPER_SMALL_MODEL_NAME))

# --- END MODEL OPTIONS ---

MODELS_PATH := /app/models

BIND_MOUNT_OPTIONS := ro
OS := $(shell uname -s)
ifeq ($(OS),Linux)
BIND_MOUNT_OPTIONS := Z,ro
endif

.PHONY: all
all: build download-model-whisper-small run

.PHONY: build
build:
podman build -t $(IMAGE) . -f Containerfile

.PHONY: download-model-whisper-small
download-model-whisper-small:
cd ../../models && \
curl -s -S -L -f $(WHISPER_SMALL_MODEL_URL) -z $(WHISPER_SMALL_MODEL_NAME) -o $(WHISPER_SMALL_MODEL_NAME).tmp && mv -f $(WHISPER_SMALL_MODEL_NAME).tmp $(WHISPER_SMALL_MODEL_NAME) 2>/dev/null || rm -f $(WHISPER_SMALL_MODEL_NAME).tmp $(WHISPER_SMALL_MODEL_NAME)

.PHONY: download-model-whisper-base
download-model-whisper-base:
cd ../../models && \
curl -s -S -L -f $(WHISPER_BASE_MODEL_URL) -z $(WHISPER_BASE_MODEL_NAME) -o $(WHISPER_BASE_MODEL_NAME).tmp && mv -f $(WHISPER_BASE_MODEL_NAME).tmp $(WHISPER_BASE_MODEL_NAME) 2>/dev/null || rm -f $(WHISPER_BASE_MODEL_NAME).tmp $(WHISPER_BASE_MODEL_NAME)

.PHONY: run
run:
cd ../../models && \
podman run -d --rm -it -p $(PORT):$(PORT) -v ./$(SELECTED_MODEL_NAME):$(MODELS_PATH)/$(SELECTED_MODEL_NAME):$(BIND_MOUNT_OPTIONS) -e HOST=0.0.0.0 -e MODEL_PATH=$(MODELS_PATH)/$(SELECTED_MODEL_NAME) -e PORT=$(PORT) $(IMAGE)
18 changes: 15 additions & 3 deletions model_servers/whispercpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ To build a Whisper model service container image from this directory,
```bash
podman build -t whisper:image .
```
or

```bash
make -f Makefile build
```

### Download Whisper model

Expand All @@ -19,10 +24,13 @@ You can to download the model from HuggingFace. There are various Whisper models
- **small**
- Download URL: [https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin](https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin)

- **base.en**
- Download URL: [https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin](https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin)

```bash
cd ../models
wget --no-config --quiet --show-progress -O ggml-small.bin <Download URL>
cd ../
cd ../../models
curl -sLO <Download URL>
cd ../model_servers/whispercpp
```

### Deploy Model Service
Expand All @@ -42,5 +50,9 @@ podman run --rm -it \
whisper:image
```

or using the make command:

`make -f Makefile run`

By default, a sample `jfk.wav` file is included in the whisper image. This can be used to test with.
The environment variable `AUDIO_FILE`, can be passed with your own audio file to override the default `/app/jfk.wav` file within the whisper image.
3 changes: 1 addition & 2 deletions model_servers/whispercpp/src/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! bin/bash
#!/bin/bash

./server -tr --model ${MODEL_PATH} --host ${HOST:=0.0.0.0} --port ${PORT:=8001}

0 comments on commit c13d712

Please sign in to comment.