Commit 9a64250b authored by duanjinfei's avatar duanjinfei

init commit

parents
Pipeline #797 failed with stages
File added
# The .dockerignore file excludes files from the container build process.
#
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Exclude Git files
.git
.github
.gitignore
# Exclude Python cache files
__pycache__
.mypy_cache
.pytest_cache
.ruff_cache
# Exclude Python virtual environment
/venv
name: Push to Replicate
on:
# Workflow dispatch allows you to manually trigger the workflow from GitHub.com
# Go to your repo, click "Actions", click "Push to Replicate", click "Run workflow"
workflow_dispatch:
inputs:
model_name:
description: 'Enter the model name, like "alice/bunny-detector". If unset, this will default to the value of `image` in cog.yaml.'
# # Uncomment these lines to trigger the workflow on every push to the main branch
# push:
# branches:
# - main
jobs:
push_to_replicate:
name: Push to Replicate
# If your model is large, the default GitHub Actions runner may not
# have enough disk space. If you need more space you can set up a
# bigger runner on GitHub.
runs-on: ubuntu-latest
steps:
# This action cleans up disk space to make more room for your
# model code, weights, etc.
- name: Free disk space
uses: jlumbroso/free-disk-space@v1.3.1
with:
tool-cache: false
docker-images: false
- name: Checkout
uses: actions/checkout@v4
# This action installs Docker buildx and Cog (and optionally CUDA)
- name: Setup Cog
uses: replicate/setup-cog@v2
with:
# If you set REPLICATE_API_TOKEN in your GitHub repository secrets,
# the action will authenticate with Replicate automatically so you
# can push your model
token: ${{ secrets.REPLICATE_API_TOKEN }}
# If you trigger the workflow manually, you can specify the model name.
# If you leave it blank (or if the workflow is triggered by a push), the
# model name will be derived from the `image` value in cog.yaml.
- name: Push to Replicate
run: |
if [ -n "${{ inputs.model_name }}" ]; then
cog push r8.im/${{ inputs.model_name }}
else
cog push
fi
.vscode
__pycache__
.cog
# Configuration for Cog ⚙️
# Reference: https://cog.run/yaml
build:
# set to true if your model requires a GPU
gpu: true
# a list of ubuntu apt packages to install
system_packages:
- ffmpeg
# python version in the form '3.11' or '3.11.4'
python_version: "3.11.4"
# a list of packages in the format <package-name>==<version>
python_packages:
- numpy==1.23.5
- torch==2.0.1
- torchaudio
- funasr
- modelscope
- huggingface
- huggingface_hub
# commands run after the environment is setup
run:
- "echo env is ready!"
- "echo another command if needed"
# predict.py defines how predictions are run on your model
predict: "predict.py:Predictor"
# Prediction interface for Cog ⚙️
# https://cog.run/python
from cog import BasePredictor, Input, Path, BaseModel
from funasr import AutoModel
# from modelscope import snapshot_download
from typing import List
class ModelOutput(BaseModel):
key: str
text: str
class Predictor(BasePredictor):
def setup(self) -> None:
"""Load the model into memory to make running multiple predictions efficient"""
# model_dir = snapshot_download(
# 'iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-onnx')
# vad_dir = snapshot_download(
# 'iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx')
# punc_dir = snapshot_download(
# 'iic/punc_ct-transformer_cn-en-common-vocab471067-large-onnx')
self.model = AutoModel(
model="paraformer-zh", vad_model="fsmn-vad", punc_model="ct-punc")
def predict(
self,
batch_size: int = Input(description="BatchSize input", default=300),
awv: Path = Input(description="Grayscale input awv",
default="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/vad_example.wav"),
) -> List[str]:
try:
print("batch_size:", batch_size)
print("awv:", awv)
res = self.model.generate(
input=str(awv), batch_size_s=batch_size)
print("res:", res)
output_list = []
for item in res:
text = item['text']
output_list.append(text)
return output_list
except Exception as e:
print(f"{e}")
return []
from funasr import AutoModel
from modelscope import snapshot_download
# model_dir = snapshot_download(
# 'iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online')
# print("model_dir:", model_dir)
model = AutoModel(
model="/root/.cache/modelscope/hub/iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch")
res = model.generate(
input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/vad_example.wav")
print(res)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment