mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
Merge pull request #7 from BoardWare-Genius/count_time
feat: logging_time decorator
This commit is contained in:
@ -34,6 +34,11 @@ python main.py
|
|||||||
## Configuration
|
## Configuration
|
||||||
Create ".env.yaml" at the root of jarvis-models, and copy the following yaml configuration
|
Create ".env.yaml" at the root of jarvis-models, and copy the following yaml configuration
|
||||||
```yaml
|
```yaml
|
||||||
|
env:
|
||||||
|
version: 0.0.1
|
||||||
|
host: 0.0.0.0
|
||||||
|
port: 8000
|
||||||
|
|
||||||
log:
|
log:
|
||||||
level: debug
|
level: debug
|
||||||
time_format: "%Y-%m-%d %H:%M:%S"
|
time_format: "%Y-%m-%d %H:%M:%S"
|
||||||
|
|||||||
@ -7,6 +7,8 @@ from fastapi.responses import JSONResponse
|
|||||||
from injector import inject
|
from injector import inject
|
||||||
from injector import singleton
|
from injector import singleton
|
||||||
|
|
||||||
|
from ..log.logging_time import logging_time
|
||||||
|
|
||||||
from ..configuration import MeloConf
|
from ..configuration import MeloConf
|
||||||
from .blackbox import Blackbox
|
from .blackbox import Blackbox
|
||||||
|
|
||||||
@ -14,7 +16,7 @@ import soundfile
|
|||||||
from melo.api import TTS
|
from melo.api import TTS
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logging.basicConfig(level=logging.INFO)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class MeloTTS(Blackbox):
|
class MeloTTS(Blackbox):
|
||||||
@ -24,9 +26,9 @@ class MeloTTS(Blackbox):
|
|||||||
device: str
|
device: str
|
||||||
language: str
|
language: str
|
||||||
speaker: str
|
speaker: str
|
||||||
|
|
||||||
@inject
|
@logging_time(logger=logger)
|
||||||
def __init__(self, melo_config: MeloConf) -> None:
|
def model_init(self, melo_config: MeloConf) -> None:
|
||||||
self.speed = melo_config.speed
|
self.speed = melo_config.speed
|
||||||
self.device = melo_config.device
|
self.device = melo_config.device
|
||||||
self.language = melo_config.language
|
self.language = melo_config.language
|
||||||
@ -43,6 +45,10 @@ class MeloTTS(Blackbox):
|
|||||||
self.url = melo_config.url
|
self.url = melo_config.url
|
||||||
logging.info('#### Initializing MeloTTS Service in ' + self.device + ' mode...')
|
logging.info('#### Initializing MeloTTS Service in ' + self.device + ' mode...')
|
||||||
|
|
||||||
|
@inject
|
||||||
|
def __init__(self, melo_config: MeloConf) -> None:
|
||||||
|
self.model_init(melo_config)
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
return self.processing(*args, **kwargs)
|
return self.processing(*args, **kwargs)
|
||||||
|
|
||||||
@ -50,6 +56,7 @@ class MeloTTS(Blackbox):
|
|||||||
text = args[0]
|
text = args[0]
|
||||||
return isinstance(text, str)
|
return isinstance(text, str)
|
||||||
|
|
||||||
|
@logging_time(logger=logger)
|
||||||
def processing(self, *args, **kwargs) -> io.BytesIO | bytes:
|
def processing(self, *args, **kwargs) -> io.BytesIO | bytes:
|
||||||
text = args[0]
|
text = args[0]
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
|
|||||||
@ -81,7 +81,7 @@ class LogConf():
|
|||||||
time_format = "%Y-%m-%d %H:%M:%S"
|
time_format = "%Y-%m-%d %H:%M:%S"
|
||||||
filename: str | None
|
filename: str | None
|
||||||
@inject
|
@inject
|
||||||
def __init__(self,config: Configuration) -> None:
|
def __init__(self, config: Configuration) -> None:
|
||||||
self.level = config.get("log.level")
|
self.level = config.get("log.level")
|
||||||
c = config.get("log.level", default=DEFAULT_LEVEL).upper()
|
c = config.get("log.level", default=DEFAULT_LEVEL).upper()
|
||||||
level=logging._nameToLevel.get(c)
|
level=logging._nameToLevel.get(c)
|
||||||
@ -95,7 +95,10 @@ class LogConf():
|
|||||||
@singleton
|
@singleton
|
||||||
class EnvConf():
|
class EnvConf():
|
||||||
version: str
|
version: str
|
||||||
|
host: str
|
||||||
|
port: str
|
||||||
@inject
|
@inject
|
||||||
def __init__(self) -> None:
|
def __init__(self, config: Configuration) -> None:
|
||||||
self.version = "0.0.1"
|
self.version = "0.0.1"
|
||||||
|
self.host = config.get("env.host", default="0.0.0.0")
|
||||||
|
self.port = config.get("env.port", default="8080")
|
||||||
15
src/log/logging_time.py
Normal file
15
src/log/logging_time.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
def logging_time(logger: logging.Logger=None):
|
||||||
|
if logger is None:
|
||||||
|
logger = logging.getLogger("unknown_logger")
|
||||||
|
def dec(cb):
|
||||||
|
def inner(self, *args, **kwargs):
|
||||||
|
start = time.time()
|
||||||
|
result = cb(self, *args, **kwargs)
|
||||||
|
end = time.time()
|
||||||
|
logger.info(self.__class__.__name__+"."+cb.__name__ + " Time taken: " + str(end - start) + " seconds")
|
||||||
|
return result
|
||||||
|
return inner
|
||||||
|
return dec
|
||||||
@ -10,10 +10,7 @@ from scipy.io.wavfile import read
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
MATPLOTLIB_FLAG = False
|
MATPLOTLIB_FLAG = False
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
|
|
||||||
logger = logging
|
|
||||||
|
|
||||||
|
|
||||||
def load_checkpoint(checkpoint_path, model, optimizer=None):
|
def load_checkpoint(checkpoint_path, model, optimizer=None):
|
||||||
assert os.path.isfile(checkpoint_path)
|
assert os.path.isfile(checkpoint_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user