diff --git a/src/asr/asr.py b/src/asr/asr.py index dbcd0a8..f75db00 100644 --- a/src/asr/asr.py +++ b/src/asr/asr.py @@ -10,12 +10,13 @@ from ..blackbox.blackbox import Blackbox class ASR(Blackbox): - def __init__(self, config: any) -> None: - config = read_yaml(config) + def __init__(self, *args, **kwargs) -> None: + config = read_yaml(args[0]) self.paraformer = RapidParaformer(config) super().__init__(config) - async def processing(self, data: bytes): + async def processing(self, *args, **kwargs): + data = args[0] results = self.paraformer([BytesIO(data)]) if len(results) == 0: return None diff --git a/src/blackbox/audio_to_text.py b/src/blackbox/audio_to_text.py index daefdcd..e8f1201 100644 --- a/src/blackbox/audio_to_text.py +++ b/src/blackbox/audio_to_text.py @@ -8,7 +8,8 @@ from .blackbox import Blackbox class AudioToText(Blackbox): - def valid(self, data: any) -> bool : + def valid(self, *args, **kwargs) -> bool : + data = args[0] kind = filetype.guess(data) if kind is None: return False diff --git a/src/blackbox/calculator.py b/src/blackbox/calculator.py index c7a39c7..1bee3a9 100644 --- a/src/blackbox/calculator.py +++ b/src/blackbox/calculator.py @@ -7,7 +7,8 @@ class Calculator(Blackbox): """This class just for example, it show how to implement Blackbox interface.""" - def valid(self, data: any) -> bool: + def valid(self, *args, **kwargs) -> bool: + data = args[0] return isinstance(data, dict) and "op" in data and "left" in data and "right" in data def processing(self, data: dict) -> int | float: diff --git a/src/blackbox/sentiment.py b/src/blackbox/sentiment.py index 4f12156..a77180a 100644 --- a/src/blackbox/sentiment.py +++ b/src/blackbox/sentiment.py @@ -12,10 +12,12 @@ class Sentiment(Blackbox): def __init__(self) -> None: self.engine = SentimentEngine('resources/sentiment_engine/models/paimon_sentiment.onnx') - def valid(self, data: any) -> bool: + def valid(self, *args, **kwargs) -> bool: + data = args[0] return isinstance(data, str) - def processing(self, text: any) -> int: + def processing(self, *args, **kwargs) -> int: + text = args[0] return int(self.engine.infer(text)) async def fast_api_handler(self, request) -> Response: diff --git a/src/blackbox/sum.py b/src/blackbox/sum.py index 71fea56..f472a90 100644 --- a/src/blackbox/sum.py +++ b/src/blackbox/sum.py @@ -7,10 +7,12 @@ from .blackbox import Blackbox class SUM(Blackbox): - def valid(self, data: any) -> bool: + def valid(self, *args, **kwargs) -> bool: + data = args[0] return isinstance(data, list) - def processing(self, data: list) -> Coroutine[Any, Any, Any]: + def processing(self, *args, **kwargs) -> Coroutine[Any, Any, Any]: + data = args[0] return sum(data) async def fast_api_handler(self, request: Request) -> Response: diff --git a/src/blackbox/tts.py b/src/blackbox/tts.py index 9393e50..7c1cd2c 100644 --- a/src/blackbox/tts.py +++ b/src/blackbox/tts.py @@ -9,7 +9,7 @@ import time class TTS(Blackbox): - def __init__(self) -> None: + def __init__(self, *args, **kwargs) -> None: config = { 'paimon': ['resources/tts/models/paimon6k.json', 'resources/tts/models/paimon6k_390k.pth', 'character_paimon', 1], 'yunfei': ['resources/tts/models/yunfeimix2.json', 'resources/tts/models/yunfeimix2_53k.pth', 'character_yunfei', 1.1], @@ -18,12 +18,14 @@ class TTS(Blackbox): self.tts_service = TTService(*config['catmaid']) super().__init__(config) - def processing(self, text: str) -> io.BytesIO: + def processing(self, *args, **kwargs) -> io.BytesIO: + text = args[0] audio = self.tts_service.read(text) return audio - def valid(self, txt: any) -> bool: - return isinstance(txt, str) + def valid(self, *args, **kwargs) -> bool: + text = args[0] + return isinstance(text, str) async def fast_api_handler(self, request: Request) -> Response: try: