merge code repo for sensevoice and whisper
This commit is contained in:
7
Dockerfile_sensevoice
Normal file
7
Dockerfile_sensevoice
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
FROM corex:3.2.1
|
||||||
|
|
||||||
|
WORKDIR /workspace
|
||||||
|
COPY requirements_sensevoice.txt constraints_sensevoice.txt server_sensevoice.py launch_sensevoice.sh /workspace/
|
||||||
|
RUN pip install -r requirements_sensevoice.txt -c constraints_sensevoice.txt
|
||||||
|
|
||||||
|
ENTRYPOINT ["/bin/bash", "launch_sensevoice.sh"]
|
||||||
10
Dockerfile_whisper
Normal file
10
Dockerfile_whisper
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FROM zibo.harbor.iluvatar.com.cn:30000/saas/bi100-3.2.1-x86-ubuntu20.04-py3.10-poc-llm-infer:v1.2.2
|
||||||
|
|
||||||
|
RUN mkdir /workspace
|
||||||
|
WORKDIR /workspace/
|
||||||
|
|
||||||
|
COPY asr_server_whisper.py /workspace/asr_server_whisper.py
|
||||||
|
COPY ./launch_service /workspace/launch_service
|
||||||
|
COPY whisper-tiny /model
|
||||||
|
|
||||||
|
ENTRYPOINT ["./launch_service"]
|
||||||
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# tiangai100-sensevoice-funasr
|
||||||
|
# tiangai100-whisper
|
||||||
|
|
||||||
|
【语音识别】
|
||||||
|
|
||||||
|
funasr可正常照nvidia方式使用。
|
||||||
34
asr_server_whisper.py
Normal file
34
asr_server_whisper.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import torch
|
||||||
|
from transformers import pipeline
|
||||||
|
from flask import Flask, request, jsonify
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
|
asr_pipeline = pipeline(
|
||||||
|
task="automatic-speech-recognition",
|
||||||
|
model="/model",
|
||||||
|
torch_dtype=torch.float16,
|
||||||
|
device="cuda:0"
|
||||||
|
)
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
pipeline_lock = Lock()
|
||||||
|
|
||||||
|
@app.route('/recognition', methods=['POST'])
|
||||||
|
def predict():
|
||||||
|
audio_data = request.data
|
||||||
|
params = request.params
|
||||||
|
params_json = json.loads(params)
|
||||||
|
lang = params_json.get('language', 'en')
|
||||||
|
with pipeline_lock:
|
||||||
|
res = asr_pipeline(inputs=audio_data, generate_kwargs={"language": lang})
|
||||||
|
text = res['text'].strip()
|
||||||
|
return jsonify({'RecognitionStatus': 'Success', "DisplayText": text})
|
||||||
|
|
||||||
|
@app.route('/ready', methods=['GET'])
|
||||||
|
@app.route('/health', methods=['GET'])
|
||||||
|
@app.route('/health_check', methods=['GET'])
|
||||||
|
def health():
|
||||||
|
return jsonify({'status': 'ok'})
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(host='0.0.0.0', port=80)
|
||||||
1
constraints_sensevoice.txt
Normal file
1
constraints_sensevoice.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
torch==2.1.0+corex.3.2.1
|
||||||
4
launch_sensevoice.sh
Executable file
4
launch_sensevoice.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
python3 asr_server.py
|
||||||
|
|
||||||
9
launch_service
Executable file
9
launch_service
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
data
|
||||||
|
cat /proc/cpuinfo
|
||||||
|
ixsmi
|
||||||
|
export
|
||||||
|
date
|
||||||
|
|
||||||
|
python3 asr.py
|
||||||
3
requirements_sensevoice.txt
Normal file
3
requirements_sensevoice.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
funasr
|
||||||
|
fastapi
|
||||||
|
uvicorn[standard]
|
||||||
41
server_sensevoice.py
Normal file
41
server_sensevoice.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
from fastapi import FastAPI, Request
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
from funasr import AutoModel
|
||||||
|
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||||
|
import os
|
||||||
|
import torch
|
||||||
|
|
||||||
|
model_dir = os.getenv("MODEL_DIR", "/model/iic/SenseVoiceSmall")
|
||||||
|
model = None
|
||||||
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def lifespan(app: FastAPI):
|
||||||
|
global model
|
||||||
|
if model is None:
|
||||||
|
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||||
|
model = AutoModel(model=model_dir, disable_update=True, device=device)
|
||||||
|
yield
|
||||||
|
pass
|
||||||
|
|
||||||
|
app = FastAPI(lifespan=lifespan)
|
||||||
|
|
||||||
|
@app.post("/recognition")
|
||||||
|
async def asr(request: Request, language: str = "auto"):
|
||||||
|
audio_data = await request.body()
|
||||||
|
res = model.generate(input=audio_data, use_itn=True, ban_emo_unk=True)
|
||||||
|
text = rich_transcription_postprocess(res[0]["text"])
|
||||||
|
return {
|
||||||
|
"RecognitionStatus": "Success",
|
||||||
|
"DisplayText": text
|
||||||
|
}
|
||||||
|
|
||||||
|
@app.get("/health")
|
||||||
|
@app.get("/ready")
|
||||||
|
def ready():
|
||||||
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import uvicorn
|
||||||
|
uvicorn.run(app, host="0.0.0.0", port=80)
|
||||||
|
|
||||||
BIN
whisper-tiny/.msc
Normal file
BIN
whisper-tiny/.msc
Normal file
Binary file not shown.
1
whisper-tiny/.mv
Normal file
1
whisper-tiny/.mv
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Revision:master,CreatedAt:1736300537
|
||||||
Reference in New Issue
Block a user