-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
285 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
services: | ||
whisper-service: | ||
image: ${REGISTRY:-opea}/whisper:${TAG:-latest} | ||
container_name: whisper-service | ||
ports: | ||
- "7066:7066" | ||
ipc: host | ||
environment: | ||
no_proxy: ${no_proxy} | ||
http_proxy: ${http_proxy} | ||
https_proxy: ${https_proxy} | ||
restart: unless-stopped | ||
asr: | ||
image: ${REGISTRY:-opea}/asr:${TAG:-latest} | ||
container_name: asr-service | ||
ports: | ||
- "9099:9099" | ||
ipc: host | ||
environment: | ||
ASR_ENDPOINT: ${ASR_ENDPOINT} | ||
|
||
networks: | ||
default: | ||
driver: bridge |
32 changes: 32 additions & 0 deletions
32
comps/asr/deployment/docker_compose/compose_whisper_hpu.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,32 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
services: | ||
whisper-service: | ||
image: ${REGISTRY:-opea}/whisper-gaudi:${TAG:-latest} | ||
container_name: whisper-service | ||
ports: | ||
- "7066:7066" | ||
ipc: host | ||
environment: | ||
no_proxy: ${no_proxy} | ||
http_proxy: ${http_proxy} | ||
https_proxy: ${https_proxy} | ||
HABANA_VISIBLE_DEVICES: all | ||
OMPI_MCA_btl_vader_single_copy_mechanism: none | ||
runtime: habana | ||
cap_add: | ||
- SYS_NICE | ||
restart: unless-stopped | ||
asr: | ||
image: ${REGISTRY:-opea}/asr:${TAG:-latest} | ||
container_name: asr-service | ||
ports: | ||
- "3001:9099" | ||
ipc: host | ||
environment: | ||
ASR_ENDPOINT: ${ASR_ENDPOINT} | ||
|
||
networks: | ||
default: | ||
driver: bridge |
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import aiohttp | ||
from typing import List | ||
import os | ||
import requests | ||
from fastapi import File, Form, UploadFile | ||
|
||
from comps import OpeaComponent, CustomLogger, ServiceType | ||
from comps.cores.proto.api_protocol import ( | ||
AudioTranscriptionResponse, | ||
) | ||
|
||
logger = CustomLogger("opea_whisper_asr") | ||
logflag = os.getenv("LOGFLAG", False) | ||
|
||
|
||
class OpeaWhisperAsr(OpeaComponent): | ||
""" | ||
A specialized ASR (Automatic Speech Recognition) component derived from OpeaComponent for Whisper ASR services. | ||
Attributes: | ||
model_name (str): The name of the ASR model used. | ||
""" | ||
def __init__(self, name: str, description: str, config: dict = None): | ||
super().__init__(name, ServiceType.ASR.name.lower(), description, config) | ||
self.base_url = os.getenv("ASR_ENDPOINT", "http://localhost:7066/v1/audio/transcriptions") | ||
|
||
async def invoke( | ||
self, | ||
file: UploadFile = File(...), # Handling the uploaded file directly | ||
model: str = Form("openai/whisper-small"), | ||
language: str = Form("english"), | ||
prompt: str = Form(None), | ||
response_format: str = Form("json"), | ||
temperature: float = Form(0), | ||
timestamp_granularities: List[str] = Form(None), | ||
) -> AudioTranscriptionResponse: | ||
""" | ||
Invole the ASR service to generate transcription for the provided input. | ||
""" | ||
# Read the uploaded file | ||
file_contents = await file.read() | ||
|
||
# Prepare the files and data for requests.post | ||
files = { | ||
"file": (file.filename, file_contents, file.content_type), | ||
} | ||
data = { | ||
"model": model, | ||
"language": language, | ||
"prompt": prompt, | ||
"response_format": response_format, | ||
"temperature": temperature, | ||
"timestamp_granularities": timestamp_granularities, | ||
} | ||
|
||
# Send the file and model to the server | ||
response = requests.post(self.base_url, files=files, data=data) | ||
res = response.json()["text"] | ||
return AudioTranscriptionResponse(text=res) | ||
|
||
|
||
async def check_health(self) -> bool: | ||
""" | ||
Checks the health of the embedding service. | ||
Returns: | ||
bool: True if the service is reachable and healthy, False otherwise. | ||
""" | ||
try: | ||
async with aiohttp.ClientSession() as client: | ||
async with client.get(f"{self.base_url}/health") as response: | ||
# If status is 200, the service is considered alive | ||
if response.status == 200: | ||
return True | ||
except aiohttp.ClientError as e: | ||
# Handle connection errors, timeouts, etc. | ||
print(f"Health check failed: {e}") | ||
return False |
Oops, something went wrong.